ipfs-docs
ipfs-docs copied to clipboard
Clarify how to use the `x-directory` header in Curl requests.
From a hackathon participant:
I am trying to add a file in IPFS inside a specific directory via the HTTP API, can someone point me to an example in cURL? curl -F "test.json=@/2021/03/18/weather.json" 127.0.0.1:5001/api/v0/add?wrap-with-directory=true the above does not seem to create a "weather.json" file inside a directory structure "/2021/03/18" but instead it creates a file called "/2021/03/18/weather.json"
One answer I got when asking around:
The api docs explain how the multipart body works. You cannot let curl build the multipart as normal, since you need to send a x-directory part apart from the uploaded file part i think, or at least set some part header manually with the path. I never got to figure out what curl foo magic is needed and whether this is possible.
If we don't know how to use it, nobody else will either 😅
Updated answer for future use in examples:
curl -F '[email protected];encoder=base64;filename=a/b/c.gif' 'http://localhost:5001/api/v0/add?progress=true' {"Name":"a/b/c.gif","Bytes":33534} {"Name":"a/b/c.gif","Hash":"QmVCTMQrvAj1Czk4beNxD5LKP4sHYFwTwPDvc5UDTaGzPB","Size":"33548"} {"Name":"a/b","Hash":"Qmb8UKKhhqRUpgyhBK1HfdzNZKydRo5EwDj334BuUSLjPy","Size":"33601"} {"Name":"a","Hash":"Qma4t85aY6LoGYbasRidumoMZizkhRbVHkk8EV2u7DLGYg","Size":"33650"}
And docs link for the API:
https://docs.ipfs.io/reference/http/api/#request-body
Could be an easy fix to close this gap is to just put the full curl example in that part of the docs?
So, there are two things at play here, x-directory
and filename
:
You can also put x-directory parts, they don't hurt, and are needed for example to create an empty dir I think, but otherwise things are inferred from the filename header.
Just to make sure I'm understanding correctly:
-
The current example just creates a file called
/2021/03/18/weather.json
:curl -F "test.json=@/2021/03/18/weather.json" 127.0.0.1:5001/api/v0/add?wrap-with-directory=true
-
The actual command should be:
curl -F "[email protected];encoder=base64;filename=a/b/c.json" http://localhost:5001/api/v0/add?progress=true
I'm confused about the x-directory
bit. Is it required, or optional? I can't see it in any of the examples.
Exactly. The documentation should say what each header is for, and why, with examples.
On Mon, Mar 22, 2021 at 10:22 AM Johnny @.***> wrote:
Just to make sure I'm understanding correctly:
The current example just creates a file called /2021/03/18/weather.json :
curl -F "test.json=@/2021/03/18/weather.json" 127.0.0.1:5001/api/v0/add?wrap-with-directory=true
The actual command should be:
curl -F @.***;encoder=base64;filename=a/b/c.json" http://localhost:5001/api/v0/add?progress=true
I'm confused about the x-directory bit. Is it required, or optional? I can't see it in any of the examples.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ipfs/ipfs-docs/issues/704#issuecomment-804101402, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMHN3J5JEUJGDBJ7DGLX3TE5HA7ANCNFSM4ZO2AAJA .
would really appreciate help on this. My use case is uploading the 10k metadata files for an NFT collection. I cannot construct a valid request in Python since that requires opening 10k individual files. Can't find any information on the web on how to do this.