postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.84k stars 839 forks source link

[Help]Upload file via Post man #1441

Closed mit4ever closed 7 years ago

mit4ever commented 9 years ago

Hi, I upload file via Postman is not working but Advanced Rest Client is working, please help me. Thanks

abhijitkane commented 9 years ago

@tuyenlq What's the exact problem you're facing? You can check http://blog.getpostman.com/2014/01/27/enabling-chrome-developer-tools-inside-postman/ and http://blog.getpostman.com/2015/06/13/debugging-postman-requests/ to check if Postman is throwing any errors and the exact request/response payloads.

mit4ever commented 9 years ago

@abhijitkane

I cant upload file via post man :(,so i do wrong ?

Request header: capture1

Request Payload: capture2

Respone: capture3

Postman: capturepostman

Thanks

abhijitkane commented 9 years ago

Try changing files[] to files. If that doesn't help, can you post the screenshot from advanced rest client?

mit4ever commented 9 years ago

2015-09-18_9-52-16 It working. I suggest in postman cannot get path image

mit4ever commented 9 years ago

Hi,

Why closed topic ? i try upload file on postman but it not working

abhijitkane commented 9 years ago

The file name in Advanced Rest Client is fileUpload, but files[]/files in Postman. Can you change it to fileUpload in Postman as well? If not, you can select the 'binary' mode in Postman instead of 'form-data' and try uploading the file there.

kellyjandrews commented 9 years ago

@abhijitkane I'm also having some difficulty with the file upload for multipart/form-data field type.

I did notice something in the curl however, that may be causing the problem.

With Postman, the curl call uses this -F "file1=filename.jpg". In my terminal however, I have to use -F "file1=@filename.jpg".

I tested with Advanced Rest Client, and was able to upload there as well. I don't think the file select is appropriately attaching the file to the request. Hope that helps.

a85 commented 9 years ago

@abhijitkane I believe we have pushed a bug fix for that yesterday?

abhijitkane commented 9 years ago

@kellyjandrews What version of Postman are you using? Also, if the Interceptor is on, can you try turning it off?

kellyjandrews commented 9 years ago

3.0.21 - Interceptor is not on.

abhijitkane commented 9 years ago

Can you update to 3.0.22 (chrome:/extensions > Enable developer mode > Update extensions now) and check? Try uploading a small text file via the form-data section via a POST request to http://dump.getpostman.com/post.

kellyjandrews commented 9 years ago

Still omitted the @ in the -F flag. I attempted to use your route, but not sure what the form field should be called. I tried file.

abhijitkane commented 9 years ago

The http://dump.getpostman.com/post endpoint should echo the contents of the file you're sending. Are you unable to reproduce this? If not, can you check the console for any errors? (http://blog.getpostman.com/2014/01/27/enabling-chrome-developer-tools-inside-postman/)

Screenshot - screen shot 2015-10-07 at 18 16 40

kellyjandrews commented 9 years ago
<html>
    <head>
        <title>Internal Server Error</title>
    </head>
    <body>
        <h1>Internal Server Error</h1>
    </body>
</html>
abhijitkane commented 9 years ago

Even with a simple text file?

kellyjandrews commented 9 years ago

test.txt with the text "test" in it, yes.

kellyjandrews commented 9 years ago

the curl still shows this -

curl -X POST -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -H "Cache-Control: no-cache" -H "Postman-Token: abcb6497-b225-c592-01be-e9ff460ca188" -F "file=test.txt" 'http://dump.getpostman.com/post'

-F "file=test.txt" should be -F "file=@test.txt"

abhijitkane commented 9 years ago

The curl command is not what Postman actually sends. That's generated for convenience.

What if you change the URL to httpbin.org/post?

kellyjandrews commented 9 years ago

If the cUrl command is generated for convenience, it would be more convenient if it were accurate :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>
111
abhijitkane commented 9 years ago

Of course - we'll include that in the next release. For now, you can choose Shell > cURL in the preview window to get the correct cURL output. We'll look into the file upload issue and get back to you.

kellyjandrews commented 9 years ago

you know what - that makes more sense - I didn't realize there was a shell -> curl - that looks appropriate - when tested in terminal - that works fine

{
  "args": {},
  "data": "",
  "files": {
    "file": "testing\n"
  },
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Cache-Control": "no-cache",
    "Content-Length": "194",
    "Content-Type": "multipart/form-data; boundary=---011000010111000001101001; boundary=------------------------a31d9bbb3c265a14",
    "Host": "httpbin.org",
    "Postman-Token": "fcd35ead-41e4-c204-87d8-a430d1ff22bd",
    "User-Agent": "curl/7.37.1"
  },
  "json": null,
  "origin": "68.58.82.213",
  "url": "http://httpbin.org/post"
}
arawind commented 9 years ago

Facing the same issue - Postman 3.0.22 (Packaged) with Interceptor 0.2.13

Interceptor's request:

curl 'http://dump.getpostman.com/post' -H 'Origin: chrome-extension://aicmkgpgakddgnaphhhpliifpcfhicfo' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryjm9OsGs3uzVVdoIT' -H 'Accept: */*' -H 'Cache-Control: no-cache' -H 'Cookie: km_ai=hb9iwazFI3WzkVlvNCCiDgDxxH4%3D; _ga=GA1.2.1540532211.1444282899; kvcd=1444283323195; km_vs=1; km_lv=1444283323; km_uq=; mp_88b82fb04df34ce696ed11f104901795_mixpanel=%7B%22distinct_id%22%3A%20%2215045f8206b50-0623da2ee-34627807-fa000-15045f8206c61%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24search_engine%22%3A%20%22google%22%7D' -H 'Connection: keep-alive' -H 'X-FirePHP-Version: 0.0.6' -H 'DNT: 1' -H 'Postman-Token: 55114064-1a5f-6089-f81f-31e0f2831402' --data-binary $'------WebKitFormBoundaryjm9OsGs3uzVVdoIT--\r\n' --compressed

Postman's Response for above:

{
  "args": {},
  "data": "",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "en-US,en;q=0.8",
    "Cache-Control": "no-cache",
    "Connection": "close",
    "Content-Length": "44",
    "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryjm9OsGs3uzVVdoIT",
    "Cookie": "km_ai=hb9iwazFI3WzkVlvNCCiDgDxxH4%3D; _ga=GA1.2.1540532211.1444282899; kvcd=1444283323195; km_vs=1; km_lv=1444283323; km_uq=; mp_88b82fb04df34ce696ed11f104901795_mixpanel=%7B%22distinct_id%22%3A%20%2215045f8206b50-0623da2ee-34627807-fa000-15045f8206c61%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24search_engine%22%3A%20%22google%22%7D",
    "Dnt": "1",
    "Host": "127.0.0.1:8000",
    "Origin": "chrome-extension://aicmkgpgakddgnaphhhpliifpcfhicfo",
    "Postman-Token": "55114064-1a5f-6089-f81f-31e0f2831402",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
    "X-Firephp-Version": "0.0.6"
  },
  "json": null,
  "origin": "127.0.0.1",
  "url": "http://127.0.0.1:8000/post"
}

Works from DHC:

{
  "args": {}, 
  "data": "", 
  "files": {
    "abcd": "test\n"
  }, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "en-US,en;q=0.8", 
    "Connection": "close", 
    "Content-Length": "201", 
    "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundarysSTdzdLs9E6oVCz0", 
    "Cookie": "km_ai=hb9iwazFI3WzkVlvNCCiDgDxxH4%3D; _ga=GA1.2.1540532211.1444282899; kvcd=1444283323195; km_vs=1; km_lv=1444283323; km_uq=; mp_88b82fb04df34ce696ed11f104901795_mixpanel=%7B%22distinct_id%22%3A%20%2215045f8206b50-0623da2ee-34627807-fa000-15045f8206c61%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24search_engine%22%3A%20%22google%22%7D", 
    "Dnt": "1", 
    "Host": "127.0.0.1:8000", 
    "Origin": "chrome-extension://aejoelaoggembcahagimdiliamlcdmfm", 
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36", 
    "X-Firephp-Version": "0.0.6"
  }, 
  "json": null, 
  "origin": "127.0.0.1", 
  "url": "http://127.0.0.1:8000/post"
}
abhijitkane commented 9 years ago

@arawind There's an issue with file uploads through the Interceptor which we'll be fixing soon.

jemshit commented 8 years ago

I was getting error as well. I was overwriting field Content_Type in Header like this: Content-Type: multipart/form-data. Then i removed it from Header and i think Postman auto created content type, so it started to work.

sunshineo commented 8 years ago

+1 I cannot believe this does not work. I have a simple curl for upload files which works, but I just cannot do the same in Postman.

sankety commented 8 years ago

Facing the same issue in which I am able to upload file using CURL but not through postman.

mrbarletta commented 8 years ago

Solved doing what @jemshit said

tamjd1 commented 8 years ago

Solved doing what @jemshit said as well.

marky04 commented 8 years ago

Solved doing what @jemshit said

reduxdj commented 8 years ago

The problem for me is the UI file needs to be removed, and replaced, or it stops working.

xeviscc commented 8 years ago

Still having the same problem!

Check the screenshoots, in the Headers in the bottom says it sent Content-Type "text/xml" Headers: image Body: image

sdnts commented 8 years ago

@xeviscc The headers your screenshots show are actually the response headers. Is your file not being sent at all?

xeviscc commented 8 years ago

You are right, I did not notice it at the moment I posted the screenshoots. And you are right also about the file. It is notsent at all, I check the code (ie: cur) and it is not referenced.

jamesdixon commented 7 years ago

@jemshit's fix worked for me. cheers!

shivajain commented 7 years ago

It does not work for me with any of the above mentioned solutions. I do not have any interceptor in my code. Find attached screenshots. The request do not work with postman client but works fine with Advance Rest Client(chrome extension)

Seems like Advance rest client tool automatically adds the necessary details with the request while postman doesn't.
The details in ARC are : accept: application/json content-type: multipart/form-data; boundary=----WebKitFormBoundaryLH8o2JqfnQGkh9xq authorization: ASI_CLIENT client_id=481ddeb7 client_secret=732359d3acfb476964f58e1b4e8ee54f content-length: 63485 ------WebKitFormBoundaryLH8o2JqfnQGkh9xq Content-Disposition: form-data; name="fileUpload"; filename="example.pdf" Content-Type: application/pdf

I also tried the same request with CURL tool but gives the same error. Please let me know in case you have any solution for this. Thanks in advance

multipart2 multipart1

drorlupu commented 7 years ago

This seems to be broken in Postman 4.9.0 and fixed in 4.9.2

stevemcmillen commented 7 years ago

Yup. I'm on postman 4.9.3 and its been a few weeks since I used this API but now seems that Content-Length is not added to the request. Specifically if Body is "binary" then POSTMan not adding Content-Length as it should.

Note: As workaround, get the curl command from postman and where it has -d '', change to -d '@'

stevemcmillen commented 7 years ago

I'm running Version 4.10.2 and its still not working. It does work in the Chrome POSTMan App but since Chrome app is being deprecated I hope this bug can be fixed soon. This is a blocking issue for uploading files thru our APIs since we have a few that just use binary data method.

I'll log a more specific bug here: https://github.com/postmanlabs/postman-app-support/issues/2756

ghost commented 7 years ago

how to send jwt token and file from postman

tmack8001 commented 7 years ago

I also am having issues getting a "binary" body via file selection working with my API backend

shivajain commented 7 years ago

You can easily upload a binary file in postman using following steps:

stevemcmillen commented 7 years ago

This would not work for our chunked upload API since it requires passing data as binary in body and thus I need to use the "binary" method for POST.

a85 commented 7 years ago

@stevemcmillen Closing this for now but will be tracking this one that you posted. https://github.com/postmanlabs/postman-app-support/issues/2756

OfficialKeen commented 7 years ago

can you help me please? when i want to upload a file using postman,there are no respond from postman postman1 postman2

Abhijitpandia commented 7 years ago

how can i post XML data to spark server through postman

sandeepstw commented 7 years ago

i just wanted to upload image i follow all above steps..but not working.. what logic should be there in controller and model for image collection

lemonysoft commented 7 years ago

@stw-services me too...

sdnts commented 7 years ago

@stw-services @lemonsoftltd The image upload logic you're talking about would need to go in your server, so I'm afraid I won't be able to help there.

@OfficialKeen Looks like a response was received, but it isn't what you expect, can you check your server to make sure everything is in place there?

sanojqa commented 6 years ago

I need to pass request as json format with file and need to upload file using Postman. The file is in my local system. We can pass it as form-data but how can we mention the file path in json format?

thg303 commented 6 years ago

@sanojqa json does not support binary format data (like binary files). you have 2 options: 1- change the request type to "multipart/form-data" 2- convert file to base64 and send it in a field, caution: it can increase the size of transmission up to 30%.