Reputation: 2517
I have hosted my JavaEE website ImgEcho in which I have given functionality through which users can upload an image. When I implemented this website on localhost I directly gave the path where the uploaded image would be stored as "C:/ProjectName/images"
However, I cant figure out what should be my path on the hosting server.
P.S: I should ask this question to the customer support of my hosting server but they have trashy service.
Thanks in advance.
Upvotes: 0
Views: 221
Reputation: 1365
Since you have a JavaEE website, why not just make a controller method responsible for downloading the files and have the return value of the upload function be a path to the download method? That way you can store the image wherever your website has write/read access to. I can give more implementation details on request.
Upvotes: 0
Reputation: 33
Create two directory, One is for your site and another one is your storage puropose.
Advantages:
Each time an user send a server request to access his data, it will go to search a file or folder in the directory.
through chmod we can give different access permission two them.
if the storage folder is mess up with site, it would be a risque of long page load.
Upvotes: 0
Reputation: 1270
the path will be along the lines of /usr/public_html/images. Who is your hosting through?
Upvotes: 0
Reputation: 1002
Depending on what you want, there are many different things that you can do in this situation.
If you want to have a single, shared image folder, in which you store the images of all users, than I recommend that you create an images
directory within your projects root.
Otherwise, if you want to create a image storage that is per-user, than you can do the following:
-Project Root
|-User 1
|-images
|-account
|-User 2
|-images
|-account
This is a structure that contains every user in a separate folder, with the subfolders images
, which contains the images for that user, and account
, the
storage for that user's account details and other information. This is generally more structured of a setup, and will benefit you long-term, although more advanced.
For a more scalable approach, perhaps in the future if you are willing to scale up your service, I recommend getting a large external network hard drive, or NAS (Network-attached storage), and then using that for all of the image storage. This will be very advanced, and possibly pricey, which is why it would be a long-term decision, that could quite possibly benefit your company in the future, because of the scalability.
Overall, I would generally use an images
directory, regardless of the rest of the folder structure, as it is the most logically correct decision for your current situation.
EDIT: To make this setup more secure, I recommend putting the images
directory into a custom, unrecognised archive file, and then converting the data when you need to use it, and back again when a change is made. This ensures no sneaky users opening your images because it is stored in a plain folder layout.
Upvotes: 3
Reputation: 4598
What I do is run this code in a jsp :
java.io.File f = new java.io.File ("./");
try{
out.println(" f curr " + f.getCanonicalPath());
}catch(Exception e){
out.println(" Err file :" + e + ", " + f);
}
This tells me the path to the current folder of my web app, on some clouds have seen its /xyz/tomcat/temp on others a longer path.
Upvotes: 0
Reputation: 830
You should use a relative path to store it in the site. You would want something like /images/uploads
for your project. The path should be at the root of your web documents. The reason to do so is that if you move the project, things would likely break. Using a relative path ensures that you can move the project. In addition, if this is shared hosting, you won't have to worry about your files getting mixed with others.
Upvotes: 0
Reputation: 363
You can store the images inside a path in your project itself by giving a relative path.
Upvotes: 0
Reputation: 505
Create a folder in your root named "images" and save them in there. You have to adjust the rest of the references.
Upvotes: 0