diff --git a/Libraries/Blob/RCTBlobManager.mm b/Libraries/Blob/RCTBlobManager.mm index aa45072553d..2a7cdbab24d 100755 --- a/Libraries/Blob/RCTBlobManager.mm +++ b/Libraries/Blob/RCTBlobManager.mm @@ -260,6 +260,9 @@ RCT_EXPORT_METHOD(release:(NSString *)blobId) - (id)handleNetworkingResponse:(NSURLResponse *)response data:(NSData *)data { + // An empty body will have nil for data, in this case we need to return + // an empty blob as per the XMLHttpRequest spec. + data = data ?: [NSData new]; return @{ @"blobId": [self store:data], @"offset": @0, diff --git a/Libraries/Network/RCTNetworking.mm b/Libraries/Network/RCTNetworking.mm index 9e10791efc0..cd2076c88a7 100644 --- a/Libraries/Network/RCTNetworking.mm +++ b/Libraries/Network/RCTNetworking.mm @@ -441,10 +441,6 @@ RCT_EXPORT_MODULE() { RCTAssertThread(_methodQueue, @"sendData: must be called on method queue"); - if (data.length == 0) { - return; - } - id responseData = nil; for (id handler in _responseHandlers) { if ([handler canHandleNetworkingResponse:responseType]) { @@ -454,6 +450,10 @@ RCT_EXPORT_MODULE() } if (!responseData) { + if (data.length == 0) { + return; + } + if ([responseType isEqualToString:@"text"]) { // No carry storage is required here because the entire data has been loaded. responseData = [RCTNetworking decodeTextData:data fromResponse:task.response withCarryData:nil];