I try to use the blob url to display the image file on the front view and sent the data to other module via javascript like this:
for (var i = 0; i < files.length; i++) {
var imagefile_url = window.URL.createObjectURL(files[i]);
originFiles.push(imagefile_url);
imageFiles[i] = new Promise(resolve =>{
_this.autoCropImage(imagefile_url, function(imgData, blob){
resolve({blobOBJ: blob, cropped:imgData}); //blob is blob object file and imgData is blob url
});
})
}
Promise.all(imageFiles).then(value=>{
_this.props.readInputFile(value, originFiles);
});
and I display the image file by <img scr={this.state.cropped}>.
But when I want to upload the image file to imgur, I need to convert the blob url back to blob object.
I use the way to get the blob object is using the state temporary to save the blob object.
As following my code is formdata.append("image", this.state.blobOBJ), but I want to use only one key(this.state.cropped).
Is there the way to convert blob url into blob object?