joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 770 forks source link

unexpected end of stream #419

Open shen-lan opened 4 years ago

shen-lan commented 4 years ago
 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**
        }
    }
mohitpasiapac commented 4 years ago

This may help, if it still exists: https://github.com/joltup/rn-fetch-blob/issues/399#issuecomment-519080982

muhammadwaqas605 commented 3 months ago

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://', '')), );