我使用tus-js-client将文件从iPad Pro上传到TUS服务器。一切正常,直到我上传文件> 500-600MB。当文件大小超过600MB时,系统崩溃。
Error:
[Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer']
tus-js-client文档说,您可以使用Readable stream选项开始上传。我认为解决此问题的方法之一是创建可读流并将其发送到上传功能。但是我不能在react-native上执行此操作。我尝试了react-native-fetch-blob,react-native-fs,react-native-fs-stream
在github上的问题: https://github.com/tus/tus-js-client/issues/146
const upload = new tus.Upload({ uri: `${RNFS.DocumentDirectoryPath}/images/${item.image}`}, {
endpoint: 'http://192.168.1.5:1080/files/',
retryDelays: [0, 1000, 3000, 5000],
chunkSize: 1 * 1024 * 1024,
resume: true,
metadata: {
name: item.image,
filetype: item.image.substring(item.image.lastIndexOf('.') + 1).toUpperCase(),
copyright: 30
},
onError: (error) => {
console.log('Error upload:', error)
},
onProgress: (uploadedBytes, totalBytes) => {
console.log(`Progress: ${uploadedBytes / totalBytes}`)
},
onSuccess: () => {
console.log('Upload URL:', upload.url)
},
onChunkComplete: (chunkSize, bytesAccepted, bytesTotal) => {
console.log(
`chunkSize: ${bytesTotal} `)
}
})
upload.start()
})