How to use HTTP api to add a folder

Hi
I am trying to use the HTTP API to add a folder to the IPFS server. The folder’s name is source.
I tried the following cURL request:

curl -X POST -H "Content-Type:application/x-directory" -F "file=@source" "http://127.0.0.1:5001/api/v0/add"

But, I get file argument 'path' is required. So How can I use HTTP API to add a folder to my IPFS server?

The multipart request needs to be constructed like explained here: HTTP API | IPFS Docs

Your curl attempt does not do that. It is difficult or at least not trivial to use curl to upload a folder. For a start, you have to replicate the folder-tree layout as parts in the multipart request. You are just sending a single part declared as “directory” and passing a folder as File to curl, which probably does not know what to do with it. I am not sure how to make a multipart request with curl, with several parts, each with custom headers, although it’s probably not impossible.