0

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.

TommyX
  • 1
  • 3
  • If you can't access the file in the browser (because it's outside of the root directory) you can't access it with ajax either – Brett Gregson Aug 01 '16 at 09:16
  • It is not recommend to do so, but still if you want to do so than make a shortcut of that directory some where in root and you can access the directory outside of root via that shortcut. – Mayank Pandeyz Aug 01 '16 at 09:18
  • @eskimo so is there any method can make me access the file? Maybe some actions can be taken on the back-end side? – TommyX Aug 01 '16 at 09:29

0 Answers0