0

I'm trying to translate some CURL code on postman to upload a file on a server.

I have a key called "file" which is the file I want to upload. On postman, when I pass him the file path, it doesn't work (the api rejects me). On the other hand, when I tell postman that I want to send him a "file" and that I select the file, it works.

Why does it work when I select the file from postman and why doesn't it work when I pass him the path to my file on my computer?

When I give the path to the file (it doesn't work)

When I select the file from postman (it works)

Postman must be doing something in the background that I do not know and do not know ... And I need to know what it is doing so I can use it in my application

Thanks for your attention and your help ! :)

sylvaing
  • 7
  • 6
  • 1
    In my opinion, when you input path, it maybe treat as string –  Dec 30 '21 at 09:41
  • 1
    Does this answer your question? [Can Postman take a file as a variable from a path?](https://stackoverflow.com/questions/63121276/can-postman-take-a-file-as-a-variable-from-a-path) – Christian Baumann Dec 30 '21 at 15:08

2 Answers2

0

yes you are right postman does that internally.

https://i.stack.imgur.com/bWs6a.png here you are passing the file path as string but we need to send the file data

https://i.stack.imgur.com/cGg1r.png here as you pick a File instead of text postman know that you have entered the file path from there postman read that's file and sends the whole file data

for more understanding, you can check code snippets of different languages

NodeJs - Axios

var data = new FormData();
data.append('file', fs.createReadStream('/Users/filename.txt'));
-1

Well, I found the answer, not using the curl ^^

My provider who developed this CURL script explained me that it was old and unusable today. So I use a sftp server. Thanks for your answers I have read them :)

sylvaing
  • 7
  • 6