Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64 to Blob #510

Closed
quangas opened this issue Mar 11, 2017 · 7 comments
Closed

Base64 to Blob #510

quangas opened this issue Mar 11, 2017 · 7 comments

Comments

@quangas
Copy link

quangas commented Mar 11, 2017

Is there anyway we can convert the base64 image from response.data to a bytes/blob?

@marcshilling
Copy link
Contributor

You can do this yourself in JavaScript: See here. Not going to do this in our library because of the performance impact.

@abdurrahmanekr
Copy link

When I tried method that you are mentioned. I'm run across an error called "res.blob() is not a function". Because of this error I can use this method:

function urlToBlob(url) {
    return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest();
        xhr.onerror = reject;
        xhr.onreadystatechange = () => {
            if (xhr.readyState === 4) {
                resolve(xhr.response);
            }
        };
        xhr.open('GET', url);
        xhr.responseType = 'blob'; // convert type
        xhr.send();
    })
}

var data = 'data:image/png;base64,...';
urlToBlob(data)
.then(blob => {
    console.log(blob)
})

@hoh-yue
Copy link

hoh-yue commented Jul 11, 2019

Solution is not work without remote js debugging.

@Johan-dutoit
Copy link
Collaborator

FWIW React Native supports, although untested... you could try the following

const response = await fetch(...);
const blob = await response.blob();

@SudoPlz
Copy link

SudoPlz commented Nov 22, 2019

Posted an example here, thanks @Johan-dutoit https://stackoverflow.com/a/59002760/1658268

@josealvarez97
Copy link

josealvarez97 commented Oct 30, 2020

You can do this yourself in JavaScript: See here. Not going to do this in our library because of the performance impact.

Is it slower to use blob/byte arrays? I thought that was faster than base64 in most cases. What do you mean exactly by performance impact?

@snios
Copy link

snios commented Mar 10, 2021

You can do this yourself in JavaScript: See here. Not going to do this in our library because of the performance impact.

Is it slower to use blob/byte arrays? I thought that was faster than base64 in most cases. What do you mean exactly by performance impact?

I agree with you here. Blob should have less performance impact than base64 does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants