mirror of
https://github.com/appwrite/sdk-for-flutter.git
synced 2026-06-06 19:37:52 +00:00
57 lines
1.7 KiB
Markdown
57 lines
1.7 KiB
Markdown
```dart
|
|
import 'package:appwrite/appwrite.dart';
|
|
import 'package:appwrite/enums.dart' as enums;
|
|
|
|
Client client = Client()
|
|
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
|
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
|
|
|
Storage storage = Storage(client);
|
|
|
|
// Downloading file
|
|
Uint8List bytes = await storage.getFilePreview(
|
|
bucketId: '<BUCKET_ID>',
|
|
fileId: '<FILE_ID>',
|
|
width: 0, // optional
|
|
height: 0, // optional
|
|
gravity: enums.ImageGravity.center, // optional
|
|
quality: -1, // optional
|
|
borderWidth: 0, // optional
|
|
borderColor: '', // optional
|
|
borderRadius: 0, // optional
|
|
opacity: 0, // optional
|
|
rotation: -360, // optional
|
|
background: '', // optional
|
|
output: enums.ImageFormat.jpg, // optional
|
|
token: '<TOKEN>', // optional
|
|
)
|
|
|
|
final file = File('path_to_file/filename.ext');
|
|
file.writeAsBytesSync(bytes);
|
|
|
|
// Displaying image preview
|
|
FutureBuilder(
|
|
future: storage.getFilePreview(
|
|
bucketId:'<BUCKET_ID>' ,
|
|
fileId:'<FILE_ID>' ,
|
|
width:0 , // optional
|
|
height:0 , // optional
|
|
gravity: enums.ImageGravity.center, // optional
|
|
quality:-1 , // optional
|
|
borderWidth:0 , // optional
|
|
borderColor:'' , // optional
|
|
borderRadius:0 , // optional
|
|
opacity:0 , // optional
|
|
rotation:-360 , // optional
|
|
background:'' , // optional
|
|
output: enums.ImageFormat.jpg, // optional
|
|
token:'<TOKEN>' , // optional
|
|
), // 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();
|
|
}
|
|
);
|
|
```
|