I'm working on a website which provides information edition function. That means users can upload pics and those pics will be uploaded into our server and the path of that pic will be stored into the database. Our server is based on Tomcat. Now the problem is that I want users to be able to see the pic they uploaded every time they log into our website. However, when I was trying to obtain the stored pics, something happened. First, I used ajax to send the uploaded image to the server and server will send the path back:
$.ajax({
url: domain_name+ '/IotCloud-background-manager/rest/util/fileUpload',
type: 'POST',
async: true,
cache: false,
data: formData,
processData: false,
contentType: false,
success: function(result){
imgPath = result.data;
}
Here the variable imgPath is a var I defined. Then the imgPath will be stored into database and once this page is loaded, the ajax will take the path out and write it into src attribute of an img tag.
$.ajax({
url: domain_name+"/IotCloud-background-manager/rest/equipment/getAuitById",
type: "POST",
async: false,
data: { productId: productID },
success: function(result) {
if(result.data.imgPath != null) {
str = result.data.imgPath;
image = str.slice(str.lastIndexOf("/")+1);
}
}
})
if(image != '') {
$('#preview').css("display","block");
$('#preview').attr("src", "../../iot_product_img/" + image);
But the result was that I cannot achieve the pic. Browser said the image was not found. Since the image was stored outside the root directory of server, I guess the communication between two directories went wrong. Is there any method that can allow getting files from outside of server root directory? Thanks very much.