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

upload file with multipart/form-data does not work #57

Closed
dragove opened this issue Jul 21, 2021 · 4 comments
Closed

upload file with multipart/form-data does not work #57

dragove opened this issue Jul 21, 2021 · 4 comments

Comments

@dragove
Copy link

dragove commented Jul 21, 2021

I followed this example: https://github.com/AnWeber/httpyac/tree/main/examples#multipartform-data to make a file upload request.
request.http:

### upload file
POST http://127.0.0.1:9167/testing/v2/uploadExcel HTTP/1.1
Content-Type: multipart/form-data; boundary=--WebKitFormBoundary

--WebKitFormBoundary
Content-Disposition: form-data; name="file"; filename="2.xlsx"
Content-Type: application/xlsx

< ./2.xlsx
--WebKitFormBoundary

but got the following output:

=== upload file ===
POST http://127.0.0.1:9167/base-billing-manager/v2/receipt/uploadExcel
accept: */*
accept-encoding: gzip, deflate, br
content-length: 20458
content-type: multipart/form-data; boundary=--WebKitFormBoundary
user-agent: httpyac

HTTP/1.1 200 OK
access-control-allow-credentials: true
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Cookie
access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
access-control-allow-origin: *
access-control-max-age: 3600
connection: close
content-type: application/json;charset=UTF-8
date: Wed, 21 Jul 2021 07:21:42 GMT
transfer-encoding: chunked
x-application-context: application:9167

{
  "code": 10000001,
  "message": "Required request part 'file' is not present",
  "data": null
}

It seems the body part is missing in this request, could you help me find out if I've missed something in this request?

@AnWeber
Copy link
Owner

AnWeber commented Jul 21, 2021

Exactly this error also cost me a good hour yesterday. Cause with me a missing blank line between < ./2.xlsx. and the end for the multipart/form-data. The following then worked for me (used with spring endpoint)

### upload file
POST http://127.0.0.1:9167/testing/v2/uploadExcel HTTP/1.1
Content-Type: multipart/form-data; boundary=--WebKitFormBoundary

--WebKitFormBoundary
Content-Disposition: form-data; name="file"; filename="2.xlsx"
Content-Type: application/xlsx

< ./2.xlsx

--WebKitFormBoundary

I wanted to look at it again and find what the spec for multipart/form-data says about this case, but haven't had the time yet. Also, my example of this, I will check again, not that I accidentally inserted the blank line there.

@dragove
Copy link
Author

dragove commented Jul 21, 2021

Exactly this error also cost me a good hour yesterday. Cause with me a missing blank line between < ./2.xlsx. and the end for the multipart/form-data. The following then worked for me (spring endpoint)

### upload file
POST http://127.0.0.1:9167/testing/v2/uploadExcel HTTP/1.1
Content-Type: multipart/form-data; boundary=--WebKitFormBoundary

--WebKitFormBoundary
Content-Disposition: form-data; name="file"; filename="2.xlsx"
Content-Type: application/xlsx

< ./2.xlsx

--WebKitFormBoundary

I wanted to look at it again and find what the spec for multipart/form-data says about this case, but haven't had the time yet. Also, my example of this, I will check again, not that I accidentally inserted the blank line there.

I switched to Rest Client in vscode, and it worked with following modification:
change "--WebKitFormBoundary" to "----WebKitFormBoundary"
Then it worked.

Also, I've succeed posting with httpyac with adding a new blank line. Thanks.

@AnWeber
Copy link
Owner

AnWeber commented Jul 22, 2021

My PDF example was apparently special because it had a last blank line. This has obscured the error. The cause is that the file import removes a line break, but it is needed.

@AnWeber
Copy link
Owner

AnWeber commented Jul 22, 2021

Error is fixed with version 2.21.0. thx:-)

@AnWeber AnWeber closed this as completed Jul 22, 2021
vojta7 pushed a commit to vojta7/httpyac that referenced this issue Dec 12, 2022
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

2 participants