Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

.progress() not working #37

Closed
vaibhawc opened this issue Jul 4, 2016 · 7 comments
Closed

.progress() not working #37

vaibhawc opened this issue Jul 4, 2016 · 7 comments
Assignees

Comments

@vaibhawc
Copy link

vaibhawc commented Jul 4, 2016

Are you sure this works? As in my case it doesn't seem to enter in the functions and jumps directly to .then()/.catch(). It waited for the file to upload but never executed anything inside the .progress().
Or may be you could provide an example(point me to it) on how to use it.
Btw, thanks, I'm new to RN and iOS, when nothing else seemed to work, rnfb worked well.
here:
trySendingImageToServer(url,base64ImageString,tryNum){
RNFetchBlob.fetch('POST',url,{
'Authorization' : 'Basic YWRtaW46MXEydzNlNHIlVA==',
},base64ImageString)
.progress((received,total)=>{
console.log('progress',received/total);
})
.then((resp)=>{
console.log("Response : ",resp.text());
})
.catch((err)=>{
console.log("Error : ",err);
if (tryNum>0){
this.trySendingImageToServer(url,base64ImageString,tryNum-1);
console.log("Trying again.. "+tryNum);
}
else{
console.log("Not trying anymore");
Alert.alert('Please check your connection');
}
});
}

@wkh237
Copy link
Owner

wkh237 commented Jul 4, 2016

Hi @vaibhawc , thank you for your information! Looks like the progress report mechanism is broken since I change the HTTP implementation. I'll fix this issue.

@wkh237 wkh237 self-assigned this Jul 4, 2016
@wkh237
Copy link
Owner

wkh237 commented Jul 4, 2016

@vaibhawc , thank you for your assistance, this issue has been solved in 1b2d9a7 and will be included in next release 0.6.1, I'll publish this version after doing some more tests on Android.

@vaibhawc
Copy link
Author

vaibhawc commented Jul 5, 2016

Thank you @wkh237 , that was very quick and sincere. I am actually trying to send an image where I need to know progress as well handle cancel and resume. I haven't tried it yet, but will have to handle it by my own. It might be a good idea to consider such options like onCancel, onResume. Basically they are inspired by the firebase-storage-api. Or may be I should put it on separate thread.

@wkh237
Copy link
Owner

wkh237 commented Jul 5, 2016

Hi @vaibhawc , thank you for your suggestion and feedback, I've published a new version 0.6.1 on npm, please re-install the package and see if that fulfills your use case. You're welcome to leave a comment here if there's any question : ) As for the onResume and onCancel options, I think those are very important features that I'm considering to add them into this module 👍

@vaibhawc
Copy link
Author

vaibhawc commented Jul 6, 2016

Hi @wkh237 ,It works well, thank you. RNFB is an amazing problem solver for me.
But there are so many functionalities not provided in RN that might be provided by libraries like this in future. One such functionality, which I don't require, but found out while trying firebase-storage, is that FBStorage requires blob to be passed to its API's 'put()' method which essentially means I can't use RN anyhow (afaik) for FBStorage. https://firebase.google.com/docs/reference/js/firebase.storage.Reference#put
May be somebody might require it, or may be firebase may provide some alternative to it in future.
As of now, I don't have enough know-how to make one all myself or on top of RNFB (I'd love to).
If you find time, do try it out. :)
I am closing this one here, Thank you for your support. 👍

@vaibhawc vaibhawc closed this as completed Jul 6, 2016
@wkh237
Copy link
Owner

wkh237 commented Jul 7, 2016

@vaibhawc , I'm greatly appreciate your thoughtful comments that helped improve the module. Thought we can not use FireBase web SDK directly, I suppose it is possible to use its REST API alternatively. I'm not familiar with FireBase, but I'll take some time and give it a try. 👍

@Johncy1997
Copy link

RNFetchBlob.config({
            path:`${dirs.DownloadDir}/${filename}`,
            fileCache:false
            // addAndroidDownloads: {
            //     notification : true,
            //     useDownloadManager : true,
            //     description: 'TaxiJo Payment Invoice',
            //     mime:'application/pdf',
            //     mediaScannable:true,
            //     path:`${dirs.DownloadDir}/${filename}`
            // },
        })
        .fetch('GET',this.state.invoiceUrl,{
            'Cache-Control' : 'no-store'
        })
        .progress({ interval: 250 },(received,total)=>{
            console.log('progress',received/total);
            this.setState({
                downloadProgress:(received/total)*100
            })
        })
        .then(res=>{
            // RNFetchBlob.fs.stat(res.path()).then(stats=>{
            //     console.log(stats);
            // }).catch(err=>{
            //     console.log('error while getting mimetypes');
            // })
            this.setState({
                downloadProgress:0
            })
            // RNFetchBlob.fs.exists(res.path()).then(exist=>{
            //     console.log(`file ${exist ? '' : 'not'} exists`)
            // }).catch(
            //     err=>console.log('error while checking existance',err)
            // );
            if(Platform.OS === 'ios'){
                RNFetchBlob.ios.openDocument(res.path());
            }else{
                RNFetchBlob.android.actionViewIntent(res.path(),"application/pdf");
            }
        })
        .catch((errorMessage,statusCode)=>{
            console.log("error with downloading file",errorMessage)
        })

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants