how to send png image from server to display in browser via ajax

前端 未结 4 673
别跟我提以往
别跟我提以往 2021-01-04 09:37

I have been having a hard time with what must be an incredibly normal task. I upload and save images to my web server and save the path to the file in MySQL data base (this

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 10:22

    You could display a default "no access" image to users who are forbidden to access the image:

    And, on the client side:

    
    

    Alternatively, if you really really want or need to send the data via Ajax, you can Base64 encode it:

    And place the response in an img tag using the Data URI scheme

    var img = '';
    

    Given that the Base64 encoded data is significantly larger than the original, you could send the raw data and encode it in the browser using a library.


    Does that make sense to you?

提交回复
热议问题