The question is not duplicated from What is the difference between BlobBuilder and the new Blob designer?
I am making a web application. I use Blob to download the image, just in case BlobBuilder . Blob works well, but Blob does not work in the native android browser, the native Android browser uses BlobBuilder . I expected Blob and BlobBuilder return the same blob, but they did not. Here is my code:
base64toBlob: function(b64Data, contentType, sliceSize) { var BlobBuilder, blob, byteArray, byteCharacters, byteNumbers, charCodeFromCharacter, err, posIndex; if (contentType == null) { contentType = ''; } if (sliceSize == null) { sliceSize = 1024; } posIndex = b64Data.indexOf('base64,'); if (posIndex !== -1) { b64Data = b64Data.substring(posIndex + 7); } charCodeFromCharacter = function(c) { return c.charCodeAt(0); }; byteCharacters = atob(b64Data.replace(/\s/g, '')); byteNumbers = Array.prototype.map.call(byteCharacters, charCodeFromCharacter); byteArray = new Uint8Array(byteNumbers); try { blob = new Blob([byteArray.buffer], { type: contentType }); return blob; } catch (_error) { err = _error; BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; blob = new BlobBuilder(); blob.append(byteArray.buffer); return blob.getBlob(contentType); } }
I made logs when sending request
blobImg = base64toBlob(base64Data, imageType); alert(JSON.stringify(blobImg)); // alert shows {"type": "image/jpeg", "size": 10251 } when blob worked // alert shows {"type": "image/jpeg", "size": 27822 } when blobbuilder worked ajaxRequest.send(blobImg);
I tried to download the same image in all browsers. In Chrome and other browsers, I get from the magazine {"type": "image/jpeg", "size": 10251 } and successfully send the request, but in my own browser I get {"type": "image/jpeg", "size": 27822 } and the request failed with status code 0 . The Android browser runs the catch part (I think this means that the Android native browser does not support Blob). I tested in Android 4.1.2 . I did not find anything from google about the problem. I would be glad if someone helps me!
javascript blob android-browser
Ulug'bek Ro'zimboyev
source share