如何在 React Native 中制作 javascript 图像 blob 对象?

How to make javascript image blob object in react native?

我必须像这样制作图像 blob 对象:

现在我可以在 react native 中获取图像 base64 url 并将其存储在变量中:

const base64 = img.data;

我试过这种方法,但没有用:

  function b64toBlob(dataURI) {
      var byteString = atob(dataURI.split(',')[1]);
      var ab = new ArrayBuffer(byteString.length);
      var ia = new Uint8Array(ab);
      for (var i = 0; i < byteString.length; i++) {
        ia[i] = byteString.charCodeAt(i);
      }
      return new Blob([ab], {type: 'image/jpeg'});
    }
    const blob = b64toBlob(base64);

    console.log(blob);

const base64 = img.data;

现在如何在 React Native 中使用这个 base64 变量创建一个像上图一样的 blob 对象?

我是这样解决问题的:

  ImagePicker.openPicker({
                      width: 400,
                      height: 400,
                      cropping: true,
                      includeBase64: true,
                    })
                      .then(image => {
                        setImg(image);
                      })
                      .then(() => setModalVisible(prev => !prev));


  const image = {
        name: nn,
        uri: img.path,
        type: img.mime,
        size: img.size,
        lastModifiedDate: JSON.parse(img.modificationDate),
        uid: img.modificationDate,
      };
      const form = new FormData();
      form.append('file', image);
      axios
        .post('url', form, {
          headers: {
            Authorization: `bearer ${JSON.parse(token)}`,
          },
        })