---
agentTools:
  projectIndex: https://bakrypt.readme.io/llms.txt
---

# How to upload a file to IPFS and create an attachment?

[block:api-header]
{
  "title": "Upload a file"
}
[/block]

POST `https://bakrypt.io/v1/files/` || `https://testnet.bakrypt.io/v1/files/`;

The following endpoint returns an Attachment. The “file” attribute is required.

[block:api-header]
{
  "title": "Request"
}
[/block]

e.g.,

[block:code]
{
  "codes": [
    {
      "code": "/* Vanilla Javascript example using fetch and a file type input */\n\nlet accessToken = \"<access_token>\";\nlet inputFiles = document.querySelectorAll('input[type=\"file\"]');\n(async () => {\n  let auth_url =\n    `https://bakrypt.io/v1/files/` || `https://testnet.bakrypt.io/v1/files/`;\n  let payload = new FormData();\n\n  payload.set(\"file\", inputFiles.files[0]);\n\n  const createAttachmentRequest = await fetch(auth_url, {\n    method: \"POST\",\n    headers: {\n      Authorization: `Bearer ${accessToken}`,\n    },\n    body: payload,\n  });\n  \n  const jsonResponse = await createAttachmentRequest.json();\n\n  console.log(jsonResponse);\n})();",
      "language": "javascript"
    }
  ]
}
[/block]

[block:api-header]
{
  "title": "Response"
}
[/block]

application/json

[block:code]
{
  "codes": [
    {
      "code": "{\n    \"uuid\": \"6c92550e-4a9a-44b2-b638-5e5b1b3f92f5\",\n    \"file\": \"files/2022/04/20/6c92550e-4a9a-44b2-b638-5e5b1b3f92f5.jpg\",\n    \"name\": \"1724699_10154043889945118_2538982934062315849_n.jpg\",\n    \"filename\": \"6c92550e-4a9a-44b2-b638-5e5b1b3f92f5.jpg\",\n    \"size\": \"102307\",\n    \"mimetype\": \"image/jpeg\",\n    \"ipfs\": \"ipfs://QmfQnbrxnmENquAoCaidD64LfTXyhJ9VCwFMNMUBz3mSf6\",\n    \"gateway\": \"https://ipfs.io/ipfs/QmfQnbrxnmENquAoCaidD64LfTXyhJ9VCwFMNMUBz3mSf6\",\n    \"created_on\": \"2022-04-20 16:37:58.791268+00:00\"\n}\n",
      "language": "text"
    }
  ]
}
[/block]