Compressing a blob in javascript

后端 未结 2 1947
故里飘歌
故里飘歌 2021-02-04 13:09

I need to send a blob to the server with ajax, but it can end up getting somewhat large, and I\'d like to decrease upload time. I\'ve tried jszip already, but that just gave me

2条回答
  •  面向向阳花
    2021-02-04 13:13

    JS Zip will work fine just correct your syntax..

    function create_zip() {
        var zip = new JSZip();
        zip.add("recording.wav", blobfile);//here you have to give blobFile in the form of raw bits >> convert it in json notation.. or stream .. 
        zip.add("hello2.txt", "Hello Second World\n");//this is optional..
        content = zip.generate();
        location.href="data:application/zip;base64," + content;
    }
    

    you can add multiple files too..

    Just zip.file will become zip.add

    and then zip.generate() will do the rest.. as you have done,

    or refer old Post its last part of JavaScript, and NativeBridge will be helpful if you can utilize, in this post user records using Objective C that you can ignore, but sends this object using JavaScript and Socket that you can/may utilize..

    I hope this will do ... :)

提交回复
热议问题