1024programmer Java javascript-I uploaded the image to the server, but I don’t know how to access the image in the browser

javascript-I uploaded the image to the server, but I don’t know how to access the image in the browser




    
        
        
        
        

        
        
        
        
        
        
    

    
         

Photo

Take photos

Select photo

Photo preview:

  • No photos yet

  • Clear photo


    Upload


    Reply content:

    
    
    
        
            
            
            
            
    
            
            
            
            
            
            
        
    
        
             

    Photo

    Take photos

    Select photo

    Photo preview:

  • No photos yet

  • Clear photo


    Upload


    Return the path after successful upload to the browser (client server) in PHP (server)

    For image preview, the server will return the address of an image to the front-end after the upload is successful, and the front-end will display the image

    In this way, the address of the image generated by the browser can be previewed in advance without waiting for the server to return the address.
     function getObjectURL(file) {
                     var url = null;
                     if (window.createObjectURL != undefined) { // ie
                         url = window.createObjectURL(file);
                     } else if (window.URL != undefined) { // Firefox
                         url = window.URL.createObjectURL(file);
                     } else if (window.webkitURL != undefined) { // ValleySong
                         url = window.webkitURL.createObjectURL(file);
                     }
                         return url;
                 }

    After the image is uploaded successfully, the backend needs to return success information.
    Details need to be discussed with the backend.

    Look at the API interface document to see what parameters are returned. Just communicate with the backend if you need to use it.

    Save the image path into the database and then read it out

    Usually the backend returns the path to the frontend, what’s going on with your backend

    Usually the backend generates a URL for you. You can ask what the response is and type it out, or ask the backend developer directly

    Upload images through the upload interface. Usually the interface will return relevant data, such as:

    {data:{status:1,imgPath:"/xxx/xx.png"}}

    status is the status of the upload (upload successful, upload unsuccessful). If imgPath uploads successfully, it will usually give the address to access the image.

    You can access the image through the returned image address

    This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/719563

    author: admin

    Previous article
    Next article

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Contact Us

    Contact us

    181-3619-1160

    Online consultation: QQ交谈

    E-mail: [email protected]

    Working hours: Monday to Friday, 9:00-17:30, holidays off

    Follow wechat
    Scan wechat and follow us

    Scan wechat and follow us

    Follow Weibo
    Back to top
    首页
    微信
    电话
    搜索