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
Most Efficient Way to Get Next Letter in the Alphabet Using PHP
Recreate Original PHP Array from Print_R Output
Boolean Variables Posted Through Ajax Being Treated as Strings in Server Side
How to Serve an Image with Laravel
How to Get the Home Directory from a PHP Cli Script
Laravel/Intervention Image Class - Class Not Found
Is This the Most Efficient Way to Get and Remove First Line in File
Native PHP Support in Visual Studio 2010
How to Run Matlab Code for Isolated Spoken Words Recognition from PHP
Copy Large Files (Over 2 Gb) in PHP
How to Determine Whether It's a Mobile Device with PHP
How to Use Composer to Autoload Classes from Outside the Vendor
How to Validate Phone Number Using PHP
Writing JSON Object to .JSON File on Server
Laravel Auth:Attempt() Will Not Persist Login
Laravel Many to Many Self Referencing Table Only Works One Way