How to replace the deprecated BlobBuilder with the new Blob constructor?

前端 未结 2 510
-上瘾入骨i
-上瘾入骨i 2020-12-18 05:57

Since Blobbuilder is deprecated and I have recently decided to use a new facial recognition API I am having a hard time switching over to just \"blob\".

func         


        
2条回答
  •  萌比男神i
    2020-12-18 06:26

    Switching from BlobBuilder to Blob is quite straightforward. Try the following backwards-compatible code (the stuff in the catch block is your original code):

    ...
        try {
            return new Blob([ab], {type: mimeString});
        } catch (e) {
            // The BlobBuilder API has been deprecated in favour of Blob, but older
            // browsers don't know about the Blob constructor
            // IE10 also supports BlobBuilder, but since the `Blob` constructor
            //  also works, there's no need to add `MSBlobBuilder`.
            var BlobBuilder = window.WebKitBlobBuilder || window.MozBlobBuilder;
            var bb = new BlobBuilder();
            bb.append(ab);
            return bb.getBlob(mimeString);
        }
    }
    

提交回复
热议问题