rn-fetch-blob
rn-fetch-blob copied to clipboard
unexpected end of stream
trafficstars
async uploadMedia(fileObj) {
try {
this.props.Store.changeReqLoading(true);
let UserInfo = JSON.parse(await AsyncStorage.getItem('UserInfo'));
let uploadRes = await RNFetchBlob.fetch('post', `${this.state.uploadBaseUrl}whistlecloud/v1/illegal/uploadContrastFile`, {
Authorization: UserInfo.accessToken,
userId: UserInfo.userId,
'Content-Type': 'multipart/form-data',
}, [
{ name: 'file', filename: 'voice.mp4', type: fileObj.mime, data: RNFetchBlob.wrap(fileObj.path) },
{ name: 'userId', data: UserInfo.userId },
]
)
let resData = JSON.parse(uploadRes.data);
console.warn(resData);
if (resData.code === 0) {
this.setState({
uploadUrl: resData.msg
})
} else {
RnAlert('上传失败!')
}
this.props.Store.changeReqLoading(false);
} catch (err) {
this.props.Store.changeReqLoading(false);
console.warn(err) **//unexpected end of stream**
}
}
This may help, if it still exists: https://github.com/joltup/rn-fetch-blob/issues/399#issuecomment-519080982
i use RNFetchBlob.config({ trusty: true, timeout: 1500, })
to fix this issue add .config before .fetch ==> await RNFetchBlob.config({
trusty: true,
timeout: 1500,
}).fetch(
Below is my code : ===>
const response = await RNFetchBlob.config({ trusty: true, timeout: 1500, }).fetch( 'PUT', res?.data?.data?.url, { 'Content-Type': result[0]?.type, }, RNFetchBlob.wrap(result[0]?.uri.replace('file://', '')), );