7070        <div class="ide" data-lang="javascript" data-lang-label="Web SDK">
7171            <pre class="line-numbers"><code class="prism language-javascript" data-prism>import { Client, Storge } from "appwrite";
7272
73- const client = new Client();
74- 
75- client
73+ const client = new Client()
7674    .setEndpoint('https://[HOSTNAME_OR_IP]/v1')
7775    .setProject('[PROJECT_ID]');
7876
7977const storage = new Storage(client);
8078
81- const promise = storage.createFile('[BUCKET_ID]', ID.unique(), document.getElementById('uploader').files[0]);
79+ const promise = storage.createFile(
80+     '[BUCKET_ID]',
81+     ID.unique(),
82+     document.getElementById('uploader').files[0]
83+ );
8284
8385promise.then(function (response) {
8486    console.log(response); // Success
@@ -94,58 +96,38 @@ promise.then(function (response) {
9496            <pre class="line-numbers"><code class="prism language-dart" data-prism>import 'package:appwrite/appwrite.dart';
9597
9698void main() { // Init SDK
97-   Client client = Client();
98-   Storage storage = Storage(client);
99- 
100-   client
101-     .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
102-     .setProject('5df5acd0d48c2') // Your project ID
103-   ;
104-   Future result = storage.createFile(
99+   final client = Client()
100+     .setEndpoint('https://[HOSTNAME_OR_IP]/v1')
101+     .setProject('[PROJECT_ID]');
102+ 
103+   final storage = Storage(client);
104+ 
105+   final file = await storage.createFile(
105106    bucketId: '[BUCKET_ID]',
106-     fileId: '[FILE_ID]' ,
107+     fileId: ID.unique() ,
107108    file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
108109  );
109- 
110-   result
111-     .then((response) {
112-       print(response);
113-     }).catchError((error) {
114-       print(error.response);
115-   });
116110}</code></pre>
117111        </div>
118112    </li>
119113    <li>
120114        <h3>Android</h3>
121115        <div class="ide" data-lang="kotlin" data-lang-label="Android SDK">
122-             <pre class="line-numbers"><code class="prism language-kotlin" data-prism>import androidx.appcompat.app.AppCompatActivity
123- import android.os.Bundle
124- import kotlinx.coroutines.GlobalScope
125- import kotlinx.coroutines.launch
126- import io.appwrite.Client
116+             <pre class="line-numbers"><code class="prism language-kotlin" data-prism>import io.appwrite.Client
127117import io.appwrite.services.Storage
128118
129- class MainActivity : AppCompatActivity() {
130-     override fun onCreate(savedInstanceState: Bundle?) {
131-         super.onCreate(savedInstanceState)
132-         setContentView(R.layout.activity_main)
133- 
134-         val client = Client(applicationContext)
135-             .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
136-             .setProject("5df5acd0d48c2") // Your project ID
137- 
138-         val storage = Storage(client)
139- 
140-         GlobalScope.launch {
141-             val response = storage.createFile(
142-                 bucketId = "[BUCKET_ID]",
143-                 fileId = "[FILE_ID]",
144-                 file = File("./path-to-files/image.jpg"),
145-             )
146-             val json = response.body?.string()        
147-         }
148-     }
119+ suspend fun main() {
120+     val client = Client(applicationContext)
121+         .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
122+         .setProject("5df5acd0d48c2") // Your project ID
123+ 
124+     val storage = Storage(client)
125+ 
126+     val file = storage.createFile(
127+         bucketId = "[BUCKET_ID]",
128+         fileId = ID.unique(),
129+         file = File("./path-to-files/image.jpg"),
130+     )
149131}</code></pre>
150132        </div>
151133    </li>
@@ -156,16 +138,19 @@ class MainActivity : AppCompatActivity() {
156138
157139func main() async throws {
158140    let client = Client()
159-       .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint 
160-       .setProject("5df5acd0d48c2") // Your project ID 
141+       .setEndpoint("https://[HOSTNAME_OR_IP]/v1")
142+       .setProject("[PROJECT_ID]") 
161143
162144    let storage = Storage(client)
145+ 
163146    let file = try await storage.createFile(
164147        bucketId: "[BUCKET_ID]",
165-         fileId: "[FILE_ID]",
166-         file: File(name: "image.jpg", buffer: yourByteBuffer)
148+         fileId: ID.unique(),
149+         file: InputFile.fromBuffer(yourByteBuffer,
150+             filename: "image.jpg",
151+             mimeType: "image/jpeg"
152+         )
167153    )
168-     print(file.toMap())
169154}</code></pre>
170155        </div>
171156    </li>
0 commit comments