/api/v0/add

Add a file or directory to IPFS.

Arguments

  • quiet [bool]: Write minimal output. Required: no.

  • quieter [bool]: Write only final hash. Required: no.

  • silent [bool]: Write no output. Required: no.

  • progress [bool]: Stream progress data. Required: no.

  • trickle [bool]: Use trickle-dag format for dag generation. Required: no.

  • only-hash [bool]: Only chunk and hash - do not write to disk. Required: no.

  • wrap-with-directory [bool]: Wrap files with a directory object. Required: no.

  • chunker [string]: Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash. Required: no.

  • raw-leaves [bool]: Use raw blocks for leaf nodes. Required: no.

  • nocopy [bool]: Add the file using filestore. Implies raw-leaves. (experimental). Required: no.

  • fscache [bool]: Check the filestore for pre-existing blocks. (experimental). Required: no.

  • cid-version [int]: CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. Passing version 1 will cause the raw-leaves option to default to true. Required: no.

  • hash [string]: Hash function to use. Implies CIDv1 if not sha2-256. (experimental). Required: no.

  • inline [bool]: Inline small blocks into CIDs. (experimental). Required: no.

  • inline-limit [int]: Maximum block size to inline. (experimental). Default: 32. Required: no.

  • pin [bool]: Pin locally to protect added files from garbage collection. Default: true. Required: no.

  • to-files [string]: Add reference to Files API (MFS) at the provided path. Required: no.

  • preserve-mode [bool]: Apply existing POSIX permissions to created UnixFS entries. Disables raw-leaves. (experimental). Required: no.

  • preserve-mtime [bool]: Apply existing POSIX modification time to created UnixFS entries. Disables raw-leaves. (experimental). Required: no.

  • mode [uint]: Custom POSIX file mode to store in created UnixFS entries. Disables raw-leaves. (experimental). Required: no.

  • mtime [int64]: Custom POSIX modification time to store in created UnixFS entries (seconds before or after the Unix Epoch). Disables raw-leaves. (experimental). Required: no.

  • mtime-nsecs [uint]: Custom POSIX modification time (optional time fraction in nanoseconds). Required: no.

Request Body

Argument path is of file type. This endpoint expects one or several files (depending on the command) in the body of the request as 'multipart/form-data'.

The add command not only allows adding files, but also uploading directories and complex hierarchies.

This happens as follows: Every part in the multipart request is a directory or a file to be added to IPFS.

Directory parts have a special content type application/x-directory. These parts do not carry any data. The part headers look as follows:

File parts carry the file payload after the following headers:

The above file includes its path in the "folderName/file.txt" hierarchy and IPFS will therefore be able to add it inside "folderName". The parts declaring the directories are optional when they have files inside and will be inferred from the filenames. In any case, a depth-first traversal of the directory tree is recommended to order the different parts making the request.

The Abspath header is included for filestore/urlstore features that are enabled with the nocopy option and it can be set to the location of the file in the filesystem (within the IPFS root), or to its full web URL.

Response

On success, the call to this endpoint will return with 200 and the following body:

cURL Example

curl -X POST -F file=@myfile "http://127.0.0.1:5001/api/v0/add?quiet=<value>&quieter=<value>&silent=<value>&progress=<value>&trickle=<value>&only-hash=<value>&wrap-with-directory=<value>&chunker=<value>&raw-leaves=<value>&nocopy=<value>&fscache=<value>&cid-version=<value>&hash=<value>&inline=<value>&inline-limit=32&pin=true&to-files=<value>&preserve-mode=<value>&preserve-mtime=<value>&mode=<value>&mtime=<value>&mtime-nsecs=<value>"


Last updated