joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 787 forks source link

react-native-photos-framework Error: RNFetchBlob.fetchBlobForm failed to create request body #221

Open pdkn opened 6 years ago

pdkn commented 6 years ago

In order to support iCloud assets we're using https://github.com/olofd/react-native-photos-framework. This returns URI's that are prefixed with "photos://" When trying to wrap the URI and send for upload it responds "Error: RNFetchBlob.fetchBlobForm failed to create request body"

example code

const result = await RNFetchBlob.fetch(
      "POST",
      API_BASE_URI + VIDEO_UPLOAD,
      {
        "Content-Type": "multipart/form-data",
      },
      [
        {
          name: "file",
          filename: media.filename,
          type: media.mimeType,
          data: RNFetchBlob.wrap(media.uri),
        },
        { name: "upload_preset", data: UPLOAD_PRESET_UNSIGNED },
        { name: "folder", data: folder },
      ],
    )

Any thoughts? Many thanks

minhphung210 commented 6 years ago

same issues . And here my code

        RNFetchBlob.fetch(
          'POST',
          url',
          {
            headers: {
              Authorization: this.props.token
            },
            Accept: 'application/json',
            // 'Content-Type': 'multipart/form-data',
            'Content-Type': 'multipart/form-data'
          },
          [
            {
              name: 'photo',
              // filename: response.fileName || 'CoverIMG.JPG',
              filename: 'IMG_0003.JPG',
              type: 'image/jpg',
              data: RNFetchBlob.wrap(url.replace('file://', ''))
            }
          ]
        )
recepkocur commented 5 years ago

+1

developerashish01 commented 5 years ago

+1

rodgomesc commented 5 years ago

same issues . And here my code

        RNFetchBlob.fetch(
          'POST',
          url',
          {
            headers: {
              Authorization: this.props.token
            },
            Accept: 'application/json',
            // 'Content-Type': 'multipart/form-data',
            'Content-Type': 'multipart/form-data'
          },
          [
            {
              name: 'photo',
              // filename: response.fileName || 'CoverIMG.JPG',
              filename: 'IMG_0003.JPG',
              type: 'image/jpg',
              data: RNFetchBlob.wrap(url.replace('file://', ''))
            }
          ]
        )

change 'Content-Type': 'multipart/form-data' to 'Content-Type': 'application/json' and

       JSON.stringify([
            {
              name: 'photo',
              // filename: response.fileName || 'CoverIMG.JPG',
              filename: 'IMG_0003.JPG',
              type: 'image/jpg',
              data: RNFetchBlob.wrap(url.replace('file://', ''))
            }
          ])