将图片从Blob网址上传到S3存储桶

时间:2019-01-21 12:50:36

标签: reactjs amazon-s3 blob image-uploading aws-amplify

我从承诺Example中获得Blob URL。现在,我想使用aws-amplify将其保存到s3中。由于这是一个Blob URL,如何将其推送到s3存储桶?以下是我的代码

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];
  };

此外,Blob URL也照此blob:https://fiddle.jshell.net/a0d3d404-e9e3-464d-92eb-5849d1404c08

1 个答案:

答案 0 :(得分:1)

如何获取blob,将其转换为文件对象并将其上传到S3。至于获取Blob,您可以尝试使用此rn-fetch-blob。然后转换就很简单了。

const file = new File([fetchedBlob], "filename");
相关问题