react-native-background-upload
react-native-background-upload copied to clipboard
Null responseBody when upload from ios device
I try to upload a file from an actual ios device but I get a null responseBody, but when I try to upload from a simulator everything works as expected.
Here is my code:
async function fileBackgroundUpload(filePath) {
console.log('[UPLOAD] file path', filePath);
const url = 'my-endpoint';
const uploadOptions = {
headers: {
Accept: 'application/json',
},
url,
path: filePath.replace('file://', ''),
method: 'POST',
field: 'file',
type: 'multipart',
};
console.log('[UPLOAD] options', uploadOptions);
let uploadId;
try {
uploadId = await Upload.startUpload(uploadOptions);
console.log(`[UPLOAD] background upload id: ${uploadId}`, {
filePath,
});
} catch (error) {
console.log('[UPLOAD] error while uploading file', error);
throw error;
}
const promise = new Promise((resolve, reject) => {
Upload.addListener('progress', uploadId, ({ progress }) => {
console.log('[UPLOAD] progress', progress);
});
Upload.addListener('error', uploadId, ({ error }) => {
console.log('[UPLOAD] error', { filePath, error });
reject(error);
});
Upload.addListener('cancelled', uploadId, () => {
console.log('[UPLOAD] cancelled', { filePath });
const result = {
isCanceled: true,
};
resolve(result);
});
Upload.addListener('completed', uploadId, async data => {
console.log('[UPLOAD] completed', { filePath, data });
const result = { success: true, data };
resolve(result);
});
});
return promise;
}
Same issue. But in the dev build it working fine, staging and production build facing the issue.