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

Undefined on cancel, uploadProgress, downloadProgress when wrapping fetch on RN 0.44 #370

Closed
jjdp opened this issue May 24, 2017 · 16 comments

Comments

@jjdp
Copy link

jjdp commented May 24, 2017

The object keys are there yet they are undefined when using the wrapped version. I am on RN 0.44 and rnfb 0.10.5. It is working fine though on rnfb fetch. using android simulator (does it matter)?

const Fetch = RNFetchBlob.polyfill.Fetch
window.fetch = new Fetch({}).build()

also how do you do formData on the rnfb fetch implementation, since I cant access the functions using the wrapper.

const formData = new FormData();
formData.append('key', folder + fileName);
formData.append('acl', acl);
formData.append('Content-Type', mime);
formData.append('X-Amz-Credential', x_amz_credential);
formData.append('X-Amz-Algorithm', 'AWS4-HMAC-SHA256');
formData.append('X-Amz-Date', date);
formData.append('Policy', base64Policy);
formData.append('X-Amz-Signature', signature);
formData.append('file', file);

fetch(url, {
    method : 'POST',
    body : formData
  });
@jjdp jjdp changed the title Undefined on cancel, uploadProgress, downloadProgress when wrapping fetch Undefined on cancel, uploadProgress, downloadProgress when wrapping fetch on RN 0.44 May 24, 2017
@jjdp
Copy link
Author

jjdp commented Jun 9, 2017

@wkh237 any thoughts on this?

@timothylui
Copy link

I also have this issue, even if I do const fetch = new Fetch({}).build(), the promise that comes back from fetch doesn't have uploadProgress

@wkh237
Copy link
Owner

wkh237 commented Jun 11, 2017

@jjdp , I've just fixed the issue in 5b43136, you can install the module from branch issue-370 and verify if the fix works, thank you 👍

@jjdp
Copy link
Author

jjdp commented Jun 11, 2017

im getting this error. is it building for you?
err

also tried on newly created project. same error as above

@timothylui
Copy link

I can confirm I also get the same build error. IOS uploadProgress working fine on issue-370 branch

@wkh237
Copy link
Owner

wkh237 commented Jun 12, 2017

@jjdp , thanks for the information, I'll investigate the error and update my progress later.

@wkh237
Copy link
Owner

wkh237 commented Jun 14, 2017

@jjdp, I've fixed the error, please try again, thanks.

@jjdp
Copy link
Author

jjdp commented Jun 15, 2017

@wkh237 seems ok to me. it returns uploadProgress. both loaded and total returns bytes. formula on the wiki is not good though, it sometimes returns 0%, i made a mistake on it earlier.

@timothylui can you check?

@wkh237
Copy link
Owner

wkh237 commented Jun 15, 2017

@jjdp , thanks for the heads up. Any suggestion on the wiki's instruction ? Will be appriciate about any improvements 👍

@timothylui
Copy link

@jjdp So with these changes it works fine for me on both android and ios.

The only thing I've found is replacing window.fetch works fine in debug builds but does not work on release builds. If you assign it to a variable instead and use that it works fine.

@jjdp
Copy link
Author

jjdp commented Jun 15, 2017

Math.floor(loaded/total) will always return 0 since loaded is lesser than total. You forgot to multiply it by 100.

@timothylui i see, i have only tested debug build on emulator. It maybe because when you compile release on device, the environment is not on the browser anymore. Though Im not too sure about this.

@wkh237 wkh237 closed this as completed Jun 26, 2017
maxpowa pushed a commit to maxpowa/react-native-fetch-blob that referenced this issue Jun 27, 2017
@CptMaumau
Copy link

Using 0.10.8 and after RNFetchBlob.fetch I get TypeError: undefined is not a function (near '...}).uploadProgress(function (written,...') on android emulator.

@jjdp
Copy link
Author

jjdp commented Aug 9, 2017

im still on 10.6, have you tried 10.7?

@CptMaumau
Copy link

CptMaumau commented Aug 9, 2017

Same in 10.6, 10.7 has an error that breaks runtime.

@jjdp
Copy link
Author

jjdp commented Aug 9, 2017

mine is working though, im on RN 0.45

@CptMaumau
Copy link

Working now with 10.8, didn't know the order mattered and that it has to be before .then(). Learned something, thank you for your time.

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

4 participants