vam
vam

Reputation: 502

Upload image from blob url to s3 bucket

I get blob URL from the promise Example. Now I want to save this into s3 with aws-amplify. Since this is a blob URL, How do I have to push this to s3 bucket? Following is my code

handleSaveImage = (imageUrl) => {
    const imageName = this.getImageName(this.imageRef.src);
    Storage.put(fileName, imageUrl, {
      contentType: contentTypes.IMAGE,
      level: 'private'
    })
      .then(({ key }) => {
        //console.log(key);
        this.setState({ croppedImageUrl: imageUrl });
        //onImageUpload(key);
      })
      .catch(() => {
        console.log('some error occured');
      });
  };

  getImageName = (url) => {
    console.log(url.split('/')[5].split('?')[0]);
    return url.split('/')[5].split('?')[0];
  };

Also, Blob URL goes as this blob:https://fiddle.jshell.net/a0d3d404-e9e3-464d-92eb-5849d1404c08

Upvotes: 0

Views: 6761

Answers (1)

Mohammad Harith
Mohammad Harith

Reputation: 619

How about you fetch the blob, convert it to file object and uploaded it to S3. As for fetching the blob, you can try this rn-fetch-blob. Then converting is quite straight forward.

const file = new File([fetchedBlob], "filename");

Upvotes: 2

Related Questions