# Files

# Introduction

Files are stored securely in Amazon Web Services' S3 product. This is the premium mechanism for securely storing files in the cloud with more than 100 trillion files stored globally.

# Uploading a File

To upload a file, the following steps are required:

  1. make a request must be made to the files endpoint of Vault with some basic metadata about the file.
  2. receive the response of this request, containing a signed URL that the file should be uploaded to.
  3. upload the file to the signed URL.

Once the file upload has been completed, we will run some checks on the file to make sure all is ok, and then the file is available for accessing.

The process of uploading the file will create audit log entries to describe the characteristics of the uploader, file etc.

# Accessing a File

To retrieve a file, the following steps are required:

  1. make a request to the download files endpoint
  2. receive the response of this request which contains a signed URL to download the file
  3. redirect to the signed URL to download the file

The process of downloading the file will create audit log entries to describe the characteristics of the uploader, file etc.

# Process

# Make a request to setup the upload

const authToken = "foo";
const vaultId = "bar";
const url = `https://vault.zaikio.com/api/v1/vaults/${vaultId}/files`;

const params = {
  method: "post",
  headers: {
    accept: "application/json",
    authorization: `Bearer ${authToken}`,
    content_type: "application/json"
  },
  body: {
    file: {
      path: "string",
      upload_target: "string",
      mime_type: "string",
      size: 120003232,
      checksum: "string"
    }
  },
};

fetch(url, params).then(res => res.json()).then(console.log.bind(console));

# Identifying the File

Files can be identified within a Vault by either their ID, or by using their path. In the case of IDs this is a simple process, simply provide the ID in the URL.

To use path based access, the path of the file must be Base64 encoded to make URL handling simple.

# Example
const vaultId = "a8a16e37-1678-4af0-8379-777935b17273";
const path = "C:\some\relevant\path\information\document.pdf";
const buff = new Buffer(path);
const encoded = buff.toString("base64");

console.log(`/api/v1/vaults/${vaultId}/files/${encoded}`);