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

uploadProgress callback doesn't fire. #395

Open
devloop11 opened this issue Dec 16, 2024 · 0 comments
Open

uploadProgress callback doesn't fire. #395

devloop11 opened this issue Dec 16, 2024 · 0 comments

Comments

@devloop11
Copy link

devloop11 commented Dec 16, 2024

Hi everyone,

  • react-native - 0.76.3
  • expo - 52.0.11
  • react-native-blob-util - 0.21.1

Platform: iOS

I faced an issue recently with uploading the progress bar on iOS simulator. The file was uploaded successfully but uploadProgress did not fire at all.

Here is a code of request service:

ReactNativeBlobUtil
        .fetch("POST", formattedUrl,{
        Accept: "application/json",
        "Content-Type": "multipart/form-data",
      }, [
          {
            filename: file.fileName,
            name: "file",
            type: file.mimeType,
            data: ReactNativeBlobUtil.wrap(formatedPath),
          },
        ])
        .uploadProgress({ interval: 500 }, (sent, total) => {
          console.log(sent, total);
          params?.onUploadCallback && params.onUploadCallback({ total, sent });
        })
        .then((response) => {
          /// handling response
       })

After digging deeply I found that native iOS ReactNativeBlobUtilRequest function was not called at all.
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesWritten totalBytesExpectedToSend:(int64_t)totalBytesExpectedToWrite

I could fix it by calling config method with {IOSBackgroundTask: true}. If I called it with false value the issue appeared again.

ReactNativeBlobUtil.config({ IOSBackgroundTask: true })
        .fetch({....rest of the code})

It needs to be marked in the uploading progress section because I spent almost a day to fix it. This is the only way to get uploading progress because Axios and XMLHttpRequest don't work for mobile.

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

1 participant