Upload a file

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

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

Request

e.g.,

/* Vanilla Javascript example using fetch and a file type input */

let accessToken = "<access_token>";
let inputFiles = document.querySelectorAll('input[type="file"]');
(async () => {
  let auth_url =
    `https://bakrypt.io/v1/files/` || `https://testnet.bakrypt.io/v1/files/`;
  let payload = new FormData();

  payload.set("file", inputFiles.files[0]);

  const createAttachmentRequest = await fetch(auth_url, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${accessToken}`,
    },
    body: payload,
  });
  
  const jsonResponse = await createAttachmentRequest.json();

  console.log(jsonResponse);
})();

Response

application/json

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