Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting continuous upload progress in iOS #61

Closed
akhilsanker opened this issue Aug 30, 2021 · 15 comments
Closed

Not getting continuous upload progress in iOS #61

akhilsanker opened this issue Aug 30, 2021 · 15 comments

Comments

@akhilsanker
Copy link

Hi,

In iOS the upload progress is not continuous whereas in android is getting continuous progress.

Sample code:

import RNFetchBlob from 'react-native-blob-util';

 const apiPostdata = [
    {
      data: RNFetchBlob.wrap(imageUri),
      filename: imageUri.replace(/^.*[\\\/]/, ''),
      name: imageField,
      type: 'image/jpg'
    },
    ...apiBodyUpdated
  ];

  const apiHeader: Record<string, any> = header || {
    Authorization: `Bearer ${accessToken}`,
    'Content-Type': 'multipart/form-data'
  };

  return RNFetchBlob
    .config({ IOSBackgroundTask: true })
    .fetch('POST', apiUrl, apiHeader, apiPostdata)
    .progress((received, total) => {
      if (progress) {
        progress(received / total);
      }
    })
    .uploadProgress(
      { interval: 1 }, (written, total) => {
        console.log(written / total, 'written / total'); // => always returns 1 in iOS but in android its progress from 0 to 1

        if (progress) {
          progress(written / total);
        }
      }
    )
    .then((res) => {
      if (res.respInfo.status === 201) {
        return res.json();
      }
      return res;
    })
    .catch((error) => Promise.reject(error));

Here in .progress(), written/ total always return 1 in iOS while uploading but in android value ranges from 0 to 1 thus getting a continuous progress.

Versions using:

react-native-blob-util: 0.13.13
react-native: 0.64.0
react: 17.0.1
Android Studio: 4.1 AI-201.8743.12.41.7199119
Xcode: 12.5.1/12E507

In iOS

Screen.Recording.2021-08-30.at.7.30.07.PM.mov

In Android

Screen.Recording.2021-08-30.at.7.32.07.PM.mov

Is there anything that is missing or is it the default behaviour in iOS ?

Thanks.

@cristianoccazinsp
Copy link

Can you hook into XCode and debug the lines around here? https://github.com/RonRadtke/react-native-blob-util/blob/master/ios/ReactNativeBlobUtilRequest.m#L321 (download) and https://github.com/RonRadtke/react-native-blob-util/blob/master/ios/ReactNativeBlobUtilRequest.m#L436 (upload)

Does the download handler work as expected? I have a feeling this code hasn't been updated in a long time and lots of deprecated/outdated functions are in use. I haven't tested this myself, but It looks like the bug shouldn't be hard to spot.

@akhilsanker
Copy link
Author

Hi @cristianoccazinsp ,

Thanks for the reply. Will have a try and let you know.

Thanks

@akhilsanker
Copy link
Author

Hi @cristianoccazinsp ,

Download progress also works like the same as upload progress.

Any solution for this behaviour in iOS ?

Thanks

@filipef101
Copy link

What happens when you remove .config(.. ?

@alessandro-bottamedi
Copy link

Same here, upload progress in iOS will only trigger two times, around 0.9 and then around completion... i do not have .config parameters...

@afilp
Copy link

afilp commented Jan 11, 2022

I have the same problem in iOS.

@YanaSyritskaya
Copy link

The same problem in iOS.

@liukai-2p
Copy link

有解决办法吗

@skizzo
Copy link

skizzo commented May 11, 2023

Facing this too in iOS / react-native 0.71.7 / react-native-blob-util 0.17.3. Any updates?

@filipef101
Copy link

@skizzo I would start by checking this

Can you hook into XCode and debug the lines around here? https://github.com/RonRadtke/react-native-blob-util/blob/master/ios/ReactNativeBlobUtilRequest.m#L321 (download) and https://github.com/RonRadtke/react-native-blob-util/blob/master/ios/ReactNativeBlobUtilRequest.m#L436 (upload)

Does the download handler work as expected? I have a feeling this code hasn't been updated in a long time and lots of deprecated/outdated functions are in use. I haven't tested this myself, but It looks like the bug shouldn't be hard to spot.

@skizzo
Copy link

skizzo commented May 11, 2023

First of all, thanks for your quick reply, @filipef101!

The didReceiveData() function in ReactNativeBlobUtilRequest.mm is only called a single time for a downloaded file, with the receivedBytes value set to the total file size.

I thought this might have to do with the configuration of our server where the file is loaded from, but even when trying to download an image from a placeholder service (in my case, https://placehold.co/1920x1080.png), the progress event is fired only once with 100%.

EDIT: When using a placeholder service (in my case, https://placehold.co/1920x1080.png), the progress event is fired multiple times and works correctly. So this is not a bug in the awesome react-native-blob-util module, but a misconfiguration of our server that hosts the images that are downloaded. Sorry for stealing your time!

@skizzo
Copy link

skizzo commented May 11, 2023

Just one more question, may I ask for the reason why the values for received and total in the .progress() function are returned as Strings, and not Numbers?

@RonRadtke
Copy link
Owner

Just one more question, may I ask for the reason why the values for received and total in the .progress() function are returned as Strings, and not Numbers?

That's a good question - but in general all events arepassed as string or dict to JS . For the future only strings. But likely the typecast is simply missing.

@crackhack8266
Copy link

@skizzo I am not getting progress in android as well it is coming as 0 and -1 for received and total respectively
and also download progress event is only firing once and that too when my file is downloaded completely then
any solutions please ?

@dongbach69
Copy link

I have the same problem in iOS. have anyone fixed it?

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

No branches or pull requests