React-native-fetch-blob: upload finish callback

Created on 20 May 2017  路  9Comments  路  Source: wkh237/react-native-fetch-blob

Is there any callback when upload has been finished? Basically, when I uploaded a file, i would like to show file has been uploaded. Unfortunately, the response from the server doesn't come after 5 seconds.. So we cannot use also the download progress callback.

Sample Code:

RNFetchBlob.fetch('POST', 'http://'+ SERVER_PORT +'/sfdsdf/webapi/videos', {
        //... some headers,
        'Content-Type' : 'octet-stream'
        }, [
            { name: 'file', filename: 'dsfdsfsf.mp4', data: RNFetchBlob.wrap(this.props.videoSource) },
            { name: 'title', data: this.props.title },
            { name: 'description', data: this.props.description }
        ])
        // listen to upload progress event, emit every 250ms
        .uploadProgress({ interval : 100 },(written, total) => {
            console.log('uploaded', written / total)
        })
        // listen to download progress event, every 10%
        .progress({ count : 10 }, (received, total) => {
            console.log('progress', received / total)
        })
        .then((response) => {
            console.log(response);
            // bring back the view to list
            this.props.uploadVideoSuccess();
        })
        .catch((err) => {
            console.log('error occured');
            console.log(err);
        // ...
        });

My console logs shows 99% upload done (even though file was uploaded successfully),, but is there another callback that will let me know my upload is 100%?
http://imgur.com/a/MlaUx

Below are my versions:

"react-native": "0.42.3",
"react-native-fetch-blob": "^0.10.5",

bug

Most helpful comment

@wkh237 how was it? :)

All 9 comments

@vvavepacket , I think you should change the Content-Type to multipart/form-data if you passing an Array as the body.

@wkh, thanks. but i think content type doesnt matter since react-native-fetch-blob is intelligent enough to override the header. i tried your approach and its still the same behaviour. basically the upload is finished,, but my server side logic performs some processing and will not return response immediately (delay of 5 seconds) so is there a way to inform the code that upload is finished and we are just waiting the response?

@vvavepacket , does it trigger the function in then block?

the .then block is triggered when my server side code sends a response. For example, this is timeline
(1) 7:01:01 PM - upload started
(2) 7:01:15 PM - upload finished, server doesnt send a response yet
(3) 7:01:30 PM - server starts to send response.

Between 2 and 3, the upload counter is stuck at 99% because onProgresss is not called anymore when upload is finished (onProgress on an interval, so if the upload is finished, the next interval will not be called, and then onProgress is not called). The then block is triggered when 3 starts

Okay, so .. in other words, the upload progress event missed last tick, right?

yes you got it right sir ;)

okay, I will look into this one.

is there any possible workaroud until the bug is fixed? :)

@wkh237 how was it? :)

Was this page helpful?
0 / 5 - 0 ratings