Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function dataURLToBlob(dataURL) {
var BASE64_MARKER = ';base64,';
if (dataURL.indexOf(BASE64_MARKER) == -1) {
var parts = dataURL.split(',');
var contentType = parts[0].split(':')[1];
var raw = decodeURIComponent(parts[1]);
return new Blob([raw], {type: contentType});
}
var parts = dataURL.split(BASE64_MARKER);
var contentType = parts[0].split(':')[1];
var raw = window.atob(parts[1]);
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {type: contentType});
}
@Swapnilchavan18

This comment has been minimized.

Copy link

@Swapnilchavan18 Swapnilchavan18 commented Jan 21, 2018

Its loosing image orientation(making vertical image to horizontal) for portrait images taken on ios devices, how to fix this?

@SagePtr

This comment has been minimized.

Copy link

@SagePtr SagePtr commented Apr 22, 2019

@Swapnilchavan18 no, it does not. It just converts data:uri object to blob, not knowing what's inside. Probably your data:uri was generated incorrectly, or blob is processed incorrectly later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment