Create File
Endpoint
posthttps://<REGION>.cloud.appwrite.io/v1/storage/buckets/{bucketId}/files
Description
Create a new file. Before using this route, you should create a new bucket resource using either a server integration API or directly from your Appwrite console.
Larger files should be uploaded using multiple requests with the content-range header to send a partial request with a maximum supported chunk of 5MB. The content-range header values should always be in bytes.
When the first request is sent, the server will return the File object, and the subsequent part request must include the file's id in x-appwrite-id header to allow the server to know that the partial upload is for the existing file and not for a new one.
If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally.
Required scopes
Authentication
setProject() and ensure the user is signed in. The SDK sends the session header automatically after login.Path
Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.
Body
File ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
Binary file.
An array of strings with read permissions. By default only the current user is granted with read permissions. learn more about permissions and get a full list of available permissions.
An array of strings with write permissions. By default only the current user is granted with write permissions. learn more about permissions and get a full list of available permissions.
File
File ID.
Bucket ID.
File creation date in Unix timestamp.
File update date in Unix timestamp.
File read permissions.
File write permissions.
File name.
File MD5 signature.
File mime type.
File original size in bytes.
Total number of chunks available
Total number of chunks uploaded
import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport kotlinx.coroutines.GlobalScopeimport kotlinx.coroutines.launchimport io.appwrite.Clientimport io.appwrite.models.InputFileimport io.appwrite.services.Storage
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
val client = Client(applicationContext) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID
val storage = Storage(client)
GlobalScope.launch { val response = storage.createFile( bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", file = InputFile.fromPath("file.png"), ) val json = response.body?.string() } }}Storage
Create File
Endpoint
posthttps://<REGION>.cloud.appwrite.io/v1/storage/buckets/{bucketId}/files
Description
Create a new file. Before using this route, you should create a new bucket resource using either a server integration API or directly from your Appwrite console.
Larger files should be uploaded using multiple requests with the content-range header to send a partial request with a maximum supported chunk of 5MB. The content-range header values should always be in bytes.
When the first request is sent, the server will return the File object, and the subsequent part request must include the file's id in x-appwrite-id header to allow the server to know that the partial upload is for the existing file and not for a new one.
If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally.
Required scopes
Authentication
setProject() and ensure the user is signed in. The SDK sends the session header automatically after login.Path
Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.
Body
File ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
Binary file.
An array of strings with read permissions. By default only the current user is granted with read permissions. learn more about permissions and get a full list of available permissions.
An array of strings with write permissions. By default only the current user is granted with write permissions. learn more about permissions and get a full list of available permissions.
File
File ID.
Bucket ID.
File creation date in Unix timestamp.
File update date in Unix timestamp.
File read permissions.
File write permissions.
File name.
File MD5 signature.
File mime type.
File original size in bytes.
Total number of chunks available
Total number of chunks uploaded
import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport kotlinx.coroutines.GlobalScopeimport kotlinx.coroutines.launchimport io.appwrite.Clientimport io.appwrite.models.InputFileimport io.appwrite.services.Storage
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
val client = Client(applicationContext) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID
val storage = Storage(client)
GlobalScope.launch { val response = storage.createFile( bucketId = "[BUCKET_ID]", fileId = "[FILE_ID]", file = InputFile.fromPath("file.png"), ) val json = response.body?.string() } }}