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
The Appwrite Web SDK expects a File object for file creation. This is most commonly associated with DOM file inputs.
For example, for the input tag <input type="file" id="uploader">, you would call create file like this:
const promise = storage.createFile(
'[BUCKET_ID]',
ID.unique(),
document.getElementById('uploader').files[0]
);
The Appwrite Flutter SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(path: [PATH], filename: [NAME], contentType: [MIME TYPE]) | Used to upload files from a provided path, filename and contentType are optional. Used for Flutter apps on mobile and desktop. |
InputFile.fromBytes(bytes: [BYTE LIST], filename: [NAME], contentType: [MIME TYPE]) | Used to upload files from a byte list, contentType is optional. Used for Flutter apps on the web. |
The Appwrite Android SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(path: String) | Used to upload files from a provided path. |
InputFile.fromFile(file: File) | Used to upload files from a File object. |
InputFile.fromBytes(bytes: ByteArray, filename: String, mimeType: String) | Used to upload files from a ByteArray object. Specify the file MIME type using the mimeType param. |
The Appwrite Apple SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(_ path: String) | Used to upload files from a provided path. |
InputFile.fromData(_ data: Data, filename: String, mimeType: String) | Used to upload files from a Data object. Specify the file MIME type using the mimeType param. |
InputFile.fromBuffer(_ buffer: ByteBuffer, filename: String, mimeType: String) | Used to upload files from a NIO Buffer object. Specify the file MIME type using the mimeType param. |
Server SDKs
The Appwrite NodeJS SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(filePath, filename) | Used to upload files from a provided path. |
InputFile.fromBuffer(buffer, filename) | Used to upload files from a Buffer object. |
InputFile.fromBlob(blob, filename) | Used to upload files from a Blob object. |
InputFile.fromStream(stream, filename, size) | Used to upload files from a Readable Stream object. |
InputFile.fromPlainText(content, filename) | Used to upload files in plain text. Expects a string encoded in UTF-8. |
The Appwrite PHP SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.withPath(string $path, ?string $mimeType = null, ?string $filename = null) | Used to upload files from a provided path. |
InputFile.withData(string $data, ?string $mimeType = null, ?string $filename = null) | Used to upload files from a string. |
The Appwrite Python SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.from_path(path) | Used to upload files from a provided path. |
InputFile.from_bytes(bytes) | Used to upload files from an array of bytes. |
The Appwrite Ruby SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.from_path(path) | Used to upload files from a provided path. |
InputFile.from_string(string) | Used to upload files from a String. |
InputFile.from_bytes(bytes) | Used to upload files from an array of bytes. |
The Appwrite Deno SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(filePath, filename) | Used to upload files from a provided path. |
InputFile.fromBuffer(buffer, filename) | Used to upload files from a Uint8Array object. |
InputFile.fromPlainText(content, filename) | Used to upload files in plain text. Expects a string encoded in UTF-8. |
The Appwrite Dart SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(path: [PATH], filename: [NAME], contentType: [MIME TYPE]) | Used to upload files from a provided path, filename and contentType are optional. |
InputFile.fromBytes(bytes: [BYTE LIST], filename: [NAME], contentType: [MIME TYPE]) | Used to upload files from a byte list, contentType is optional. |
The Appwrite Kotlin SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(path: String) | Used to upload files from a provided path. |
InputFile.fromFile(file: File) | Used to upload files from a File object. |
InputFile.fromBytes(bytes: ByteArray, filename: String, mimeType: String) | Used to upload files from a ByteArray object. Specify the file MIME type using the mimeType param. |
The Appwrite Swift SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.fromPath(_ path: String) | Used to upload files from a provided path. |
InputFile.fromData(_ data: Data, filename: String, mimeType: String) | Used to upload files from a Data object. Specify the file MIME type using the mimeType param. |
InputFile.fromBuffer(_ buffer: ByteBuffer, filename: String, mimeType: String) | Used to upload files from a NIO Buffer object. Specify the file MIME type using the mimeType param. |
The Appwrite .NET SDK expects an InputFile class for file inputs.
Method | Description |
InputFile.FromPath(string path) | Used to upload files from a provided path. |
InputFile.FromStream(Stream stream, string filename, string mimeType) | Used to upload files from a Stream object. Specify the file MIME type using the mimeType param. |
InputFile.FromBytes(byte[] bytes, string filename, string mimeType) | Used to upload files from an array of bytes. Specify the file MIME type using the mimeType param. |
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