Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic path for searched file.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

is there any way i can make this source search as dynamic search? i mean i don't want to set the static folder.

thanks in advance
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Yes. What have you tried? What errors have you received?
By the way, you can expose yourself to a serious security risk if you allow an application to access a file with an arbitrary path. If you are allowing a user to upload a file like an avatar image, you must take precautions by limiting file size, preventing the user from specifying a file name with control characters (like a leading '/' or '..') and so on.
 
derick nial
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
thank you for your reply,


i have tried using above method on getting the path, but what i was getting:

what i really want(the location of the image):

what other method should i use? tq.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

dee nee wrote:
i have tried using above method on getting the path, but what i was getting:



This is correct behavior. If you only specify a file name, the path is assumed to be the working directory (i.e. the directory an application started in). The File constructor does not search the file system nor does File care whether an actual file exists on the file system (There are methods to search and to check existence).
If you want to locate an image (or some other file), the best practice is to package it in your application and use Class.getResource() to locate it. This insures that your application is self-contained and easy to deploy elsewhere. If you can't do this for whatever reason, I'd put a directory on the classpath and still use Class.getResource(). Failing that, I'd make the directory name a parameter to the web application (see example here), again, trying to make the application as portable as possible. And don't forget the security precautions that I specified earlier.
 
derick nial
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks for your respond Joe;

Joe Ess wrote:If you want to locate an image (or some other file), the best practice is to package it in your application and use Class.getResource() to locate it.


do you have any example on how this is to be done?

Joe Ess wrote: don't forget the security precautions that I specified earlier.


yes thank you Joe, i already made file's size and file's type validation as you advised earlier. (:
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

dee nee wrote:Thanks for your respond Joe;
do you have any example on how this is to be done?



try this
 
    Bookmark Topic Watch Topic
  • New Topic