question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.attach didn't upload file

See original GitHub issue

We try to use superagent to upload file to our server by following this guide, https://visionmedia.github.io/superagent/#multipart-requests, on React Native project

here is our implementation code

  superagent.post(full_url)
    .field('type', 'image_type')
    .attach('file', file.uri, {contentType: 'image/png'})
    .then(response => {
      console.log(`response ${JSON.stringify(response.body)}`)
      callback(response.body)
    })
    .catch(error => {
      console.log(`error body json stringify ${JSON.stringify(error)}`)
      errorCallback(error)
    })

file.uri here is image that we got from react-native-camera

the field type was received by server, but the file was not there response from server is, more or less

{
  "status": false,
  "data": "Required request part 'file' is not present"
}

we try to change the attach parameter to .attach('file', file.base64, {contentType: 'image/png'})

and .attach('file', RNFetchBlob.wrap(file.uri), {contentType: 'image/png'})

and also .attach('file', RNFetchBlob.wrap(file.base64), {contentType: 'image/png'})

with no luck

we try to log the form data on attach function,

{
  "_parts": [
    [
      "type",
      "image_type"
    ],
    [
      "file",
      "path/to/file"
    ]
  ]
}

it clearly show that the file is there

calling the same api from Postman is success without a problem

what did we do wrong here? any feedback is welcome

thank you

Superagent: v4.0.0 React Native: v0.57.5 React: v16.6.3 rn-fetch-blob: v0.10.13

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:21

github_iconTop GitHub Comments

4reactions
sidhijakpatcommented, Dec 12, 2018

Once again, it was our mistake, the JSON Object should be:

const file = {
  uri: fileUri,
  name: 'image_name.png',
  type: `image/png`
}

Thank you again

1reaction
RodolfoGScommented, May 18, 2020

Once again, it was our mistake, the JSON Object should be:

const file = {
  uri: fileUri,
  name: 'image_name.png',
  type: `image/png`
}

Thank you again

Thank you, that works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

attach didn't upload file · Issue #1444 · ladjs/superagent - GitHub
We try to use superagent to upload file to our server by following this guide, https://visionmedia.github.io/superagent/#multipart-requests, ...
Read more >
No longer able to upload files No error message Can't close ...
I lost the ability to attach files from my computer. It acts like it's downloading but then it goes blank. No attachment.
Read more >
Unable to attach files in Outlook.com - Microsoft Support
Learn what you can do if you're unable to attach files or insrt images in Outlook.com.
Read more >
Fix Files Won't Upload To Any Web Page or Email ... - YouTube
Unable to Upload Files to Any Website or email as attachment on Google Chrome or Microsoft Edge Error Not RespondingStep 1) Clear Browsing ......
Read more >
8 Best Ways to Fix Gmail Won't Attach Files Error - Guiding Tech
The fastest way to deal with this problem is to use another email account from a different service provider. Another way can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found