-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Crash in [RNFetchBlobFS readFile] on iOS #266
Comments
BTW I'd be happy to send a PR if someone can point me in the right direction. |
@cosmith , could you provide a sample that replicates this error? It'd be helpful for me to find a way to fix it 👍 |
@cosmith , perhaps we can add a
nil (which means the call is from native context instead of JS).
__block Byte * buffer;
if(asset != nil)
{
buffer = malloc(asset.size);
[asset getBytes:buffer fromOffset:0 length:asset.size error:&err];
if(err != nil)
{
reject(@"RNFetchBlobFS readFile error", @"failed to read asset", [err localizedDescription]);
return;
}
fileContent = [NSData dataWithBytes:buffer length:asset.size];
free(buffer);
}
else
{
if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {
reject(@"RNFetchBlobFS readFile error", @"file not exists", nil);
return;
}
fileContent = [NSData dataWithContentsOfFile:path];
}
if(onComplete != nil)
+ {
+ onComplete(fileContent);
+ return;
+ } |
This is the function we use: static async sendFile(method, path, fileUri, fieldName, additionalData, onProgress = () => {}) {
let token = await Storage.getUserProperty("token");
let headers = {
"Authorization": `Token ${token}`,
"Content-Type": "multipart/form-data",
};
let source = fileUri.replace("file://", "");
let file = RNFetchBlob.wrap(source);
let formData = [
{name: fieldName, filename: fieldName + ".png", data: file},
];
for (let key in additionalData) {
formData.push({name: key, data: String(additionalData[key])});
}
this.onLoadChange(true);
return RNFetchBlob.fetch(method, Constants.ServerUrl + path, headers, formData)
.uploadProgress((written, total) => {
onProgress(written, total);
})
.then((response) => {
this.onLoadChange(false);
if (response.respInfo.status < 200 || response.respInfo.status > 399) {
Log.warn("[Server]", "error loading", path, response.data);
this.onLoadChange(false);
throw response;
}
return response.json();
}, (error) => {
this.onLoadChange(false);
Log.warn("[Server]", "error making request", path, error);
throw error;
});
} Calling this function with a file that doesn't exist crashes: Server.sendFile("POST", "/test/", "i-dont-exist.png", "photo", {}); Adding a |
@cosmith , I have committed a fix to $ npm install --save github:wkh237/react-native-fetch-blob-package#issue-266 |
Yes that fixes it! Thanks 👍 |
npm install --save github:wkh237/react-native-fetch-blob-package#issue-266 |
@jiazil this was merged in master, use the latest version |
@cosmith |
Is this issue resolved Cuz am facing it Now |
I am using react-native-image-resizer to first resize the image. the initial path is: file:///Users/nicoara/Library/Developer/CoreSimulator/Devices/CE689F2D-2A45-48F9-9F47-7A4A18DAC588/data/Containers/Data/Application/7BF23562-BF62-4870-92F9-FD72A1E92FFE/Library/Caches/B540B334-768C-435B-BFB7-988B00687338.jpg My solution was to replace the initial 'file:///Users' with '/Users'. (The above solution with https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#readfilepath-encodingpromise did not work, since the converted path is: |
Hi, I'm getting a crash when trying to send a file that doesn't exist anymore.
RNFetchBlob version 0.10.3, RN version 0.38.0
This is the stack trace I get:
It seems like the readFile method is called here and here with the
resolver
andrejecter
set tonil
.The crash happens here:
react-native-fetch-blob/src/ios/RNFetchBlobFS.m
Line 448 in d702708
I don't know why the try/catch block in readFile doesn't catch the exception. I tried adding a
if (reject != nil)
condition before the call, which works, but then the call just fails silently...Any thoughts?
The text was updated successfully, but these errors were encountered: