diff --git a/app/views/docs/storage.phtml b/app/views/docs/storage.phtml index ef7ba2473..916913647 100644 --- a/app/views/docs/storage.phtml +++ b/app/views/docs/storage.phtml @@ -70,15 +70,17 @@
import { Client, Storge } from "appwrite";
 
-const client = new Client();
-
-client
+const client = new Client()
     .setEndpoint('https://[HOSTNAME_OR_IP]/v1')
     .setProject('[PROJECT_ID]');
 
 const storage = new Storage(client);
 
-const promise = storage.createFile('[BUCKET_ID]', ID.unique(), document.getElementById('uploader').files[0]);
+const promise = storage.createFile(
+    '[BUCKET_ID]',
+    ID.unique(),
+    document.getElementById('uploader').files[0]
+);
 
 promise.then(function (response) {
     console.log(response); // Success
@@ -94,58 +96,38 @@ promise.then(function (response) {
             
import 'package:appwrite/appwrite.dart';
 
 void main() { // Init SDK
-  Client client = Client();
-  Storage storage = Storage(client);
-
-  client
-    .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
-    .setProject('5df5acd0d48c2') // Your project ID
-  ;
-  Future result = storage.createFile(
+  final client = Client()
+    .setEndpoint('https://[HOSTNAME_OR_IP]/v1')
+    .setProject('[PROJECT_ID]');
+
+  final storage = Storage(client);
+
+  final file = await storage.createFile(
     bucketId: '[BUCKET_ID]',
-    fileId: '[FILE_ID]',
+    fileId: ID.unique(),
     file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
   );
-
-  result
-    .then((response) {
-      print(response);
-    }).catchError((error) {
-      print(error.response);
-  });
 }
  • Android

    -
    import androidx.appcompat.app.AppCompatActivity
    -import android.os.Bundle
    -import kotlinx.coroutines.GlobalScope
    -import kotlinx.coroutines.launch
    -import io.appwrite.Client
    +            
    import io.appwrite.Client
     import 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 = File("./path-to-files/image.jpg"),
    -            )
    -            val json = response.body?.string()        
    -        }
    -    }
    +suspend fun main() {
    +    val client = Client(applicationContext)
    +        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
    +        .setProject("5df5acd0d48c2") // Your project ID
    +
    +    val storage = Storage(client)
    +
    +    val file = storage.createFile(
    +        bucketId = "[BUCKET_ID]",
    +        fileId = ID.unique(),
    +        file = File("./path-to-files/image.jpg"),
    +    )
     }
  • @@ -156,16 +138,19 @@ class MainActivity : AppCompatActivity() { func main() async throws { let client = Client() - .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint - .setProject("5df5acd0d48c2") // Your project ID + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") + .setProject("[PROJECT_ID]") let storage = Storage(client) + let file = try await storage.createFile( bucketId: "[BUCKET_ID]", - fileId: "[FILE_ID]", - file: File(name: "image.jpg", buffer: yourByteBuffer) + fileId: ID.unique(), + file: InputFile.fromBuffer(yourByteBuffer, + filename: "image.jpg", + mimeType: "image/jpeg" + ) ) - print(file.toMap()) }