How to POST filename to files/v3/files

SOLVE
SSchulz
Participant

This question is about this endpoint, which unfortunately has no Postman examples to checkout. 

 

I'm struggeling with accessing the POST endpoint (e.g. the "create new file" one). From the documentation, I assume the endpoint should be accessed like this:

SSchulz_0-1632124670880.png

However, I always get the response 400 Bad Request:

 

{
    "status": "error",
    "message": "Could not determine name from file",
    "correlationId": "4ee371ac-d54f-4382-bd7d-aea0bf167e85",
    "category": "BAD_REQUEST"
}

 

So the "fileName" parameter is not correct. I checked other questions on here, and it seems even though the documentation says it's a form part, it might be not? Other questions seem to send this parameter via the header of the "file" for part. 

 

I tried using "Content-Type: text/plain" and "fileName: test.txt" as headers, also "filename: test.txt" and "name: test.txt", but these did not work. So I tried using  "Content-Type: text/plain; fileName: test.txt" (also in all variations), and neither did that.

 

I also tried "Content-Disposition: form-data; name="fieldName"; filename="filename.txt"" which changes the error message:

{
	"status": "error",
	"message": "file must be specified",
	"correlationId": "ca738d9c-64a1-441a-b900-efa2b25388fe",
	"context": {
		"file": [
			"false"
		]
	},
	"category": "VALIDATION_ERROR"
}

Which probably means now the "file" part is no longer valid?

 

I feel like every question has its own way to defining the file name (but maybe I'm just bad at reading the code), and neither works for me.

 

What is the correct way to send the file name to this endpoint?

0 Upvotes
1 Accepted solution

Accepted Solutions
SSchulz
Solution
Participant

I was so close. The correct header is:

Content-Disposition: form-data; name="file"; filename="filename.txt"

Which has to be added to the "file" form data part. I have no idea if that is possible in the current version of Postman, but for Java's org.springframework.http.client.MultipartBodyBuilder it's done like this:

MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", "Hello World.")
    .header(HttpHeaders.CONTENT_DISPOSITION, "form-data; name=\"file\"; filename=\"filename.txt\"");

  

View solution in original post

0 Upvotes
2 Replies 2
SSchulz
Solution
Participant

I was so close. The correct header is:

Content-Disposition: form-data; name="file"; filename="filename.txt"

Which has to be added to the "file" form data part. I have no idea if that is possible in the current version of Postman, but for Java's org.springframework.http.client.MultipartBodyBuilder it's done like this:

MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", "Hello World.")
    .header(HttpHeaders.CONTENT_DISPOSITION, "form-data; name=\"file\"; filename=\"filename.txt\"");

  

View solution in original post

0 Upvotes
Teun
Guide | Diamond Partner

Hi @SSchulz ,

 

I found a similar issue in the community, the filename is part of the 'file' param, which is included in the header. Might help you out?



Did my answer solve your issue? Help the community by marking it as the solution.