Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 321 additions & 2 deletions src/routes/docs/products/storage/upload-download/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ The Appwrite Python SDK expects an `InputFile` class for file inputs.
| ------------------------------------------ | ------------------------------------------------------------ |
| `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. |
{% /tabsitem %}
{% /tabsitem %}

{% tabsitem #ruby title="Ruby" %}
The Appwrite Ruby SDK expects an `InputFile` class for file inputs.
Expand Down Expand Up @@ -277,7 +277,114 @@ The Appwrite .NET SDK expects an `InputFile` class for file inputs.
{% /tabsitem %}
{% /tabs %}

[TODO more download examples]
## Get file {% #get-file %}
To get a metadata about a.file, use the `getFile` method.

{% multicode %}
```js
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('5df5acd0d48c2') // 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
});
```
```dart
import 'package:appwrite/appwrite.dart';

void main() { // Init SDK
Client client = Client();
Storage storage = Storage(client);

client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
// downloading file
Future result = storage.getFile(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
).then((bytes) {
final file = File('path_to_file/filename.ext');
file.writeAsBytesSync(bytes)
}).catchError((error) {
print(error.response);
})
}

//displaying image preview
FutureBuilder(
future: storage.getFile(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
), //works for both public file and private file, for private files you need to be logged in
builder: (context, snapshot) {
return snapshot.hasData && snapshot.data != null
? Image.memory(
snapshot.data,
)
: CircularProgressIndicator();
},
);
```
```swift
import Appwrite

func main() async throws {
let client = Client()
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
let storage = Storage(client)
let byteBuffer = try await storage.getFile(
bucketId: "[BUCKET_ID]",
fileId: "[FILE_ID]"
)

print(String(describing: byteBuffer)
}
```
```kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
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://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID

val storage = Storage(client)

GlobalScope.launch {
val result = storage.getFile(
bucketId = "[BUCKET_ID]",
fileId = "[FILE_ID]"
)
println(result); // Resource URL
}
}
}
```
{% /multicode %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's something wrong here with the syntax. Is the {% /multicode %} supposed to be here?


## Download file {% #download-file %}
To download a file, use the `getFileDownload` method.
Expand Down Expand Up @@ -382,4 +489,216 @@ class MainActivity : AppCompatActivity() {
}
}
```
{% /multicode %}

## View file {% #view-file%}

To view a file, use the `getFileView` method.

{% multicode %}
```js
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('5df5acd0d48c2') // Your project ID
;

const result = storage.getFileView('[BUCKET_ID]', '[FILE_ID]');

console.log(result); // Resource URL
```
```dart
import 'package:appwrite/appwrite.dart';

void main() { // Init SDK
Client client = Client();
Storage storage = Storage(client);

client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
// downloading file
Future result = storage.getFileView(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
).then((bytes) {
final file = File('path_to_file/filename.ext');
file.writeAsBytesSync(bytes)
}).catchError((error) {
print(error.response);
})
}

//displaying image preview
FutureBuilder(
future: storage.getFileView(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
), //works for both public file and private file, for private files you need to be logged in
builder: (context, snapshot) {
return snapshot.hasData && snapshot.data != null
? Image.memory(
snapshot.data,
)
: CircularProgressIndicator();
},
);
```
```swift
import Appwrite

func main() async throws {
let client = Client()
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
let storage = Storage(client)
let byteBuffer = try await storage.getFileView(
bucketId: "[BUCKET_ID]",
fileId: "[FILE_ID]"
)

print(String(describing: byteBuffer)
}
```
```kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
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://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID

val storage = Storage(client)

GlobalScope.launch {
val result = storage.getFileView(
bucketId = "[BUCKET_ID]",
fileId = "[FILE_ID]"
)
println(result); // Resource URL
}
}
}
```
{% /multicode %}

## Get file preview {% #get-file-preview %}
To get a file preview image , use the `getFilePreview` method.
You can learn more about the **image manupulation options** in [this guide](/docs/products/storage/images).

{% multicode %}
```js
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('5df5acd0d48c2') // Your project ID
;

const result = storage.getFilePreview('[BUCKET_ID]', '[FILE_ID]');

console.log(result); // Resource URL
```
```dart
import 'package:appwrite/appwrite.dart';

void main() { // Init SDK
Client client = Client();
Storage storage = Storage(client);

client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
// downloading file
Future result = storage.getFilePreview(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
).then((bytes) {
final file = File('path_to_file/filename.ext');
file.writeAsBytesSync(bytes)
}).catchError((error) {
print(error.response);
})
}

//displaying image preview
FutureBuilder(
future: storage.getFilePreview(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
), //works for both public file and private file, for private files you need to be logged in
builder: (context, snapshot) {
return snapshot.hasData && snapshot.data != null
? Image.memory(
snapshot.data,
)
: CircularProgressIndicator();
},
);
```
```swift
import Appwrite

func main() async throws {
let client = Client()
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
let storage = Storage(client)
let byteBuffer = try await storage.getFilePreview(
bucketId: "[BUCKET_ID]",
fileId: "[FILE_ID]"
)

print(String(describing: byteBuffer)
}
```
```kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
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://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID

val storage = Storage(client)

GlobalScope.launch {
val result = storage.getFilePreview(
bucketId = "[BUCKET_ID]",
fileId = "[FILE_ID]"
)
println(result); // Resource URL
}
}
}
```
{% /multicode %}