Files
react-native/Libraries
Jordan Becker e1b698c5f2 fix(RCTBlobManager): Prevent RCTConvert error for allowed null blob types (#32397)
Summary:
While reworking our media picker, I ended up replacing the RNFetchBlob library to use `fetch()`, leveraging React Native's file resolver (especially to interpret `photos://` URI paths).

The migration process was pretty straightforward, however I kept getting RCTConvert errors when calling `fetch` with a `PUT` method and a blob body:

```
JSON value '<null>' of type NSNull cannot be converted to NSString

+[RCTConvert NSString:]
    RCTConvert.m:59
-[RCTBlobManager handleNetworkingRequest:]
-[RCTNetworking processDataForHTTPQuery:callback:]
-[RCTNetworking buildRequest:completionBlock:]
-[RCTNetworking sendRequest:callback:]
__invoking___
-[NSInvocation invoke]
-[NSInvocation invokeWithTarget:]
-[RCTModuleMethod invokeWithBridge:module:arguments:]

Test Plan:
I'll put my `fetch` snippet here. This is using a third-party library in order to get a signed URL, but it is otherwise pretty straightforward.

This snippet would trigger an error before the changes introduced by this PR.

```js
// Setup (specific to third-party lib)
const key = `file/path/in/bucket`
const params = {
  Key: key,
  Bucket: 'my.awesome.bucket',
}
const s3url = await s3.getSignedUrl('putObject', params)

// Letting RN handle how to retrieve a platform-specific resource URI
const localFetch = await fetch(localPath)
// Getting the blob to upload as octet-stream
const blob = await localFetch.blob()

// Actually uploading
await fetch(s3url, {
  method: 'PUT',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/octet-stream',
  },
  body: blob,
})
```

Reviewed By: RSNara

Differential Revision: D31625636

Pulled By: sota000

fbshipit-source-id: a7770018bc3ff2f41321b1bd26ec145b86b18784
2021-10-15 18:56:17 -07:00
..
2021-10-12 18:27:47 -07:00
2021-09-16 22:24:10 -07:00
2021-09-16 22:24:10 -07:00
2021-09-28 14:50:41 -07:00
2021-07-01 09:04:46 -07:00
2021-08-26 01:06:44 -07:00
2021-04-26 22:57:55 -07:00
2021-08-24 07:21:56 -07:00
2021-08-24 07:21:56 -07:00