joltup / rn-fetch-blob

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

Use 'NSURLSessionUploadTask' when upload large file #523

Open YuanfuC opened 4 years ago

YuanfuC commented 4 years ago

When upload the large file which is 400MB

The file load action will make the memory increase to very high, some device may crashed.

NSData * bodyBytes = [NSData dataWithContentsOfFile:orgPath ];  // Will load all file into RAM
[request setHTTPBody:bodyBytes];

Exist issue #487 Resolve:

Use NSURLSessionUploadTask and setup the file path to upload file. Don't load the file into NSData as the Http-Body

 NSURLSessionUploadTask *task = [session uploadTaskWithRequest:req fromFile:[NSURL URLWithString:filePath]];
danlupascu commented 4 years ago

I have tried using your fork and I'm still getting a memory error when trying to upload a large file on iOS (700MB). I am still getting a memory error: Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer'.

It seems to be triggered by this: [formData appendData:content]; link

YuanfuC commented 4 years ago

I have tried using your fork and I'm still getting a memory error when trying to upload a large file on iOS (700MB). I am still getting a memory error: Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer'.

It seems to be triggered by this: [formData appendData:content]; link

I upload large file and config the request like this:
The Content-Type and the path is require. Maybe you can have try

return RNFetchBlob.fetch('POST', url, {
      'Content-Type': 'application/octet-stream',
      'uploadid': uploadId,
      'offset': offset,
      'size': String(size),
      'transfer-ios': 'upload-file'
    }, RNFetchBlob.wrap(path))
meiqi1992 commented 3 years ago

用你的版本修改了,我也没有效果,700M的视频 上传就崩溃

YuanfuC commented 3 years ago

用你的版本修改了,我也没有效果,700M的视频 上传就崩溃

是否是参数调用的问题,需要使用 stream 上传的参数