axios / axios

Promise based HTTP client for the browser and node.js
https://axios-http.com
MIT License
105.47k stars 10.91k forks source link

onUploadProgress event is not being fired - React Native #6015

Open halid96 opened 11 months ago

halid96 commented 11 months ago

Describe the bug

onUploadProgress event is not firing now.

I tried it with both 1.51 and 1.3.4 version, not working.

But I know that 1.3.4 was working, so the problem is related to another package probably, this can be React Native prob, or Expo.

console.log() not fires...

        ```
       const response = await axios.post(apiUrl, formData, {
            headers: {
                'Content-Type': 'multipart/form-data',
                'Accept': 'application/json',
            },
            onUploadProgress: function ({ loaded, total, progress, bytes, estimated, rate, upload = true }) {
                let percentCompleted = (progress * 100).toFixed(0);
                console.log('percentCompleted', percentCompleted);
                uploadPercentCompleted.current = percentCompleted;
            },
            withCredentials: true,
        })
        ```

To Reproduce

No response

Code snippet

No response

Expected behavior

No response

Axios Version

1.5.1

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

"react": "18.2.0",
"react-native": "0.72.3",
"expo": "^49.0.6",

Additional context/Screenshots

No response

deagwon97 commented 11 months ago

My app is also experiencing the same issue. I just confirmed that it works well in version 1.5.0

Youngemmy5956 commented 11 months ago

console.log('Before axios.post is called'); // Check if this log statement is reached

const response = await axios.post(apiUrl, formData, { headers: { 'Content-Type': 'multipart/form-data', 'Accept': 'application/json', }, onUploadProgress: function ({ loaded, total, progress, bytes, estimated, rate, upload = true }) { let percentCompleted = (progress * 100).toFixed(0); console.log('percentCompleted', percentCompleted); uploadPercentCompleted.current = percentCompleted; }, withCredentials: true, });

console.log('After axios.post is called'); // Check if this log statement is reached

teckbeng-payboy commented 9 months ago

any fixes for this? mine will just straight show 100 for the percentageValue

zsomborgellerfi commented 8 months ago

@halid96 I am having the same problems with React native, did you manage to find a workaround for this?

suhaotian commented 7 months ago

Maybe migrate to xior?

xior similar API with axios, use fetch and plugins support, more liteweight.

Here is the example of upload file with progress plugin support(not real progress, simulated):

https://github.com/suhaotian/xior?tab=readme-ov-file#upload-file

Any questions or feedback please feel free to create issue

flygomel commented 6 months ago

same

tamagutchi commented 5 months ago

+1

does not work with 1.5.0 nor with 1.6.8

l364cyv1 commented 5 months ago

It does work on production build (v1.6.8), but on expo dev client build it does not

igorpimentel23 commented 5 months ago

not working on 1.6.8 on expo dev build but it works on production build

UmarbekSaidov commented 3 months ago

My app is also experiencing the same issue. I just confirmed that it works well in version 1.5.0

it worked fine for me in the same version

Example Code

Neiso commented 1 month ago

I confirm that it does not work with expo:

    "expo": "50",
    "react": "18.2.0",
    "react-native": "0.73.6",
     "axios": "1.7.4",

with snippet:

  const uploadImage = async (image: Image): Promise<string | false> => {
    try {
      const uri = getUri(path)
      const imagesFilePath = Platform.OS === 'ios' ? image.uri.replace('file://', '') : uri;

      const formData = new FormData();
      formData.append('image', {
        uri: imagesFilePath,
        type: image.mimeType,
        name: image.fileName,
      });

      const res = await axios.put(`${URI}`, formData, {
        headers: {
          'Content-Type': 'multipart/form-data',
        },
        // Never gets fired
        onUploadProgress: (progressEvent) => {
          const progress = Math.round((progressEvent.loaded / (progressEvent.total || 1)) * 100);
          setProgress(progress)
        }
      })

      // Successfully uploaded the file 
      return res.data
    } catch (err) {
      // ...
    }
  }