try {
await appwriteService.init();
// Create a signed URL that includes authentication
final result = await appwriteService.storage.getFilePreview(
bucketId: "patient_profile_images",
fileId: "67d96a039e2087bf7399",
);
debugPrint('🌐 AppwriteService: Result: $result');
} catch (e) {
debugPrint('❌ AppwriteService $e');
}
}, child: Text("Get Image preview ")),```
#getting error for Image preview
7 messages · Page 1 of 1 (latest)
error flutter: 🌐 AppwriteService: Result: [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 72, 0, 72, 0, 0, 255, 219, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 192, 0,
getting binary data ?
Get file preview doesn't create a signed URL. In flutter, it returns the bytes for the file
so how to use this for preview in flutter
do have to download first and then preview it ?UInt8List bytes = await storage.getFileDownload( bucketId: '<BUCKET_ID>', fileId: '<FILE_ID>', )
got it ```import 'package:appwrite/appwrite.dart';
Client client = Client()
.setEndpoint('https://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: ImageGravity.center, // optional
quality: 0, // optional
borderWidth: 0, // optional
borderColor: '', // optional
borderRadius: 0, // optional
opacity: 0, // optional
rotation: -360, // optional
background: '', // optional
output: ImageFormat.jpg, // 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: ImageGravity.center, // optional
quality:0 , // optional
borderWidth:0 , // optional
borderColor:'' , // optional
borderRadius:0 , // optional
opacity:0 , // optional
rotation:-360 , // optional
background:'' , // optional
output: ImageFormat.jpg, // 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();
}
);