Upload and download

You can upload and download files both programmatically using SDKs or through the Appwrite Console.

Create file

After you create a bucket or have navigated to bucket details, you can access the Files tab so you can upload, view, delete and update files in the bucket using the Appwrite project's dashboard. You can also perform all those operations from Appwrite's client SDK, server SDKs, and REST APIs as long as you have the proper permission.

When you are in the Files tab, you can click Add File and select a file to upload. If the bucket is configured to accept the file type and size you are uploading, your file will be uploaded, and you will see the file in the list of files.

You can also upload files programmatically using our SDKs:

import { Client, Storage } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('<PROJECT_ID>');

const storage = new Storage(client);

const promise = storage.createFile(
    '[BUCKET_ID]',
    ID.unique(),
    document.getElementById('uploader').files[0]
);

promise.then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});

Large files

When you are trying to upload any files above 5MB, you will need to upload them in chunks for better reliability and performance. If you're using an Appwrite SDK, this is handled automatically. If you're not using an SDK, you can learn more about REST API file handling.

InputFile

Every language and platform handles file inputs differently. This section documents the expected input type of each SDK. Where applicable, Appwrite provides an InputFile class to accept multiple file sources, like paths, buffers, streams, or plain text.

Client SDKs

    Server SDKs

      Get file

      To get a metadata about a.file, use the getFile method.

      import { Client, Storage } from "appwrite";
      
      const client = new Client();
      
      const storage = new Storage(client);
      
      client
          .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
          .setProject('<PROJECT_ID>') // Your project ID
      ;
      
      const promise = storage.getFile('[BUCKET_ID]', '[FILE_ID]');
      
      promise.then(function (response) {
          console.log(response); // Success
      }, function (error) {
          console.log(error); // Failure
      });
      

      Download file

      To download a file, use the getFileDownload method.

      import { Client, Storage } from "appwrite";
      
      const client = new Client();
      
      const storage = new Storage(client);
      
      client
          .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
          .setProject('<PROJECT_ID>') // Your project ID
      ;
      
      const result = storage.getFileDownload('[BUCKET_ID]', '[FILE_ID]');
      
      console.log(result); // Resource URL
      

      Get File Preview

      To get a file preview image , use the getFilePreview method.

      import { Client, Storage } from "appwrite";
      
      const client = new Client();
      
      const storage = new Storage(client);
      
      client
          .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
          .setProject('<PROJECT_ID>') // Your project ID
      ;
      
      const result = storage.getFilePreview('[BUCKET_ID]', '[FILE_ID]');
      
      console.log(result); // Resource URL
      

      View File

      To view a file, use the getFileView method.

      import { Client, Storage } from "appwrite";
      
      const client = new Client();
      
      const storage = new Storage(client);
      
      client
          .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
          .setProject('<PROJECT_ID>') // Your project ID
      ;
      
      const result = storage.getFileView('[BUCKET_ID]', '[FILE_ID]');
      
      console.log(result); // Resource URL