JavaScript Blob to download a binary file creating corrupted files

后端 未结 1 1427
傲寒
傲寒 2021-01-29 05:37

I have a binary file (python pickle file, to be exact). Whenever such a file is requested, I create one on server side, and then send it to the client via flask\'s

相关标签:
1条回答
  • 2021-01-29 06:07

    Weirdly enough, I was looking into this answer, which worked. So, I added :

    xhrFields: {
        responseType:'blob'
    },
    

    in the AJAX request, which solved the problem for me.

    I have absolutely no idea, why this worked, so can someone give a better answer than this?


    At MDN Docs:

    The values supported by responseType are the following:
    An empty responseType string is treated the same as "text", the default type.
    arraybuffer
    The response is a JavaScript ArrayBuffer containing binary data.
    blob
    The response is a Blob object containing the binary data.
    ...
    
    0 讨论(0)
提交回复
热议问题