3

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?

2
  • 1
    use the blob you already got. don't convert it back to a blob Commented Mar 17, 2018 at 17:25
  • Might interest you even if not really the same question: stackoverflow.com/questions/49145422/… Commented Mar 19, 2018 at 11:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.