react-native-documents / document-picker

Document Picker for React Native
https://react-native-documents.github.io/
MIT License
1.35k stars 437 forks source link

Status 500 Current request is not a multipart request #565

Closed marry1822 closed 2 years ago

marry1822 commented 2 years ago

Hey. After Expo eject the file uploading stopped working. Now I'm getting the "Current request is not a multipart request" error.

const pickFile = async () => {
    let result = await DocumentPicker.pickSingle({});
  };

the result looks like:

{"fileCopyUri": null, 
  "name": "Example.pdf", 
  "size": 62255, 
  "type": "application/pdf", 
  "uri": "file:///private/var/mobile/Containers/Data/Application/4A1846BA-C2C3-457E-AA77-09E8A0328FC8/tmp/com.sibiSoft.Native.Mobile.pdf"}

then I do:

const formData = new FormData();
  formData.append('files', result);

const sendData = () => {
    try {
      resourceAPI
        .uploadFile(folderId, formData, login)
        .then(res => {
          if (res) {
            Alert.alert('Success');`
          } catch (error) {
      console.log(error);
    }

where resourceAPI.uploadFile:

async uploadFile(folderId, file, credits) {
    return await axios({
      method: 'post',
      data: file,
      url: `${baseURL}api/addFile/${folderId}`,
      cache: 'no-cache',
      headers: {
        Authorization: `Basic ${base64.encode(
          `${credits.username}:${credits.password}`,
        )}`,
      },
    });

All the time I'm getting the error, what could be the reason? Is it a frontend or backend error?

vonovak commented 2 years ago

Hello, thanks for asking. I don't know if the problem is caused in the backend or in your app.

However, to upload files, please have a look at the docs in the readme: https://github.com/rnmods/react-native-document-picker#how-to-upload-picked-files

Thank you 🙂