Skip to content

Commit e1b698c

Browse files
habovhfacebook-github-bot
authored andcommitted
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
1 parent f319c1a commit e1b698c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Libraries/Blob/RCTBlobManager.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ - (NSDictionary *)handleNetworkingRequest:(NSDictionary *)data
262262
NSDictionary *blob = [RCTConvert NSDictionary:data[@"blob"]];
263263

264264
NSString *contentType = @"application/octet-stream";
265-
NSString *blobType = [RCTConvert NSString:blob[@"type"]];
265+
NSString *blobType = [RCTConvert NSString:RCTNilIfNull(blob[@"type"])];
266266
if (blobType != nil && blobType.length > 0) {
267267
contentType = blob[@"type"];
268268
}

0 commit comments

Comments
 (0)