Returning a Blob with JSON

Javascript fetch handle both json and blob

Since you want to go down two fairly different paths, this is one of the relatively-rare situations where you probably want to nest handlers:

fetch('flowers.jpg').then(function(response) {
if (response.ok) {
return response.blob().then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
myImage.src = objectURL;
});
} else {
return response.json().then(function(jsonError) {
// ...
});
}
}).catch(function(error) {
console.log('There has been a problem with your fetch operation: ', error.message);
});

Can't transform Blob coming from a JSON into file

Look at your json. by var pictureBlob = profileMap['picture']; this line you will get a map

{
"type" : "Buffer",
"data" : [47, 57, ......]
}

so to get the blob file you need to use

//getting the blob from json
var pictureBlob = profileMap['picture']['data'];
//convert it to Uint8List
var image = base64.decode(pictureBlob);

then use the image as Image.memory(image);

Angular 5 manage http get with blob response and json errors

As in docs "The only way to read content from a Blob is to use a FileReader." https://developer.mozilla.org/en-US/docs/Web/API/Blob.

EDIT:
If you need part of blob, you can do a slice, which returns new Blob,
and then use file reader.



Related Topics



Leave a reply



Submit