我需要使用rn-fetch-blob
本机反应在服务器上上传大文件。问题是当文件大小超过 ~10MB 时,应用程序崩溃而没有错误消息。文件路径来自react-native-share-extension
. 平台 - iOS。在 Android 和 iOS 模拟器上一切正常。
const uploadUri = Platform.OS === 'ios' ? value.replace('file://', '') : value;
const headers = {
'Content-Type': 'multipart/form-data',
Accept: 'application/json',
};
const jsonData = [
{
name: 'title',
data: title,
},
{
name: 'file',
filename: `${Math.random()
.toString(36)
.substr(2, 9)}-${new Date().getTime()}.${extension}`,
type: filetype,
data: RNFetchBlob.wrap(uploadUri),
},
];
RNFetchBlob.fetch('POST', url, headers, jsonData)
.then(res => {
console.log('uploaded')
})
.catch(err => {
console.log('error');
});
我试过使用readStream
它也没有帮助
RNFetchBlob.fs
.readStream(
uploadUri,
'base64',
4095,
100
)
.then(ifstream => {
ifstream.open();
ifstream.onData(chunk => {
data += chunk
});
ifstream.onEnd(() => {
console.log('end');
});
});