Rank 1: Thread
Hello,
How can I pick an image, and then upload it to appwrite without saving it?
Votes
0
Replies
20
Participants
Unknown
Messages
21
Rank 1: Thread
Hello,
How can I pick an image, and then upload it to appwrite without saving it?
https://pub.dev/packages/image_picker
Is this something you are looking for?
Rank 1: Thread
yes, but i have to save the imahe ig?
I didn't understand what do you mean by saving ? This package picks the image from your gallery
Rank 1: Thread
yes, but when i want to upload it to appwrite i have to pass the path and for that I have to save it right?
save what actually? If i am right the image is already in the gallery right?
Rank 1: Thread
ah bruh
Rank 1: Thread
did like that but got an error:
Future _getImage() async { final ImagePicker picker = ImagePicker(); final XFile? image = await picker.pickImage(source: ImageSource.gallery);
final storage = Storage(db());
final file = await storage.createFile( bucketId: '650fe518eed83eab7514', fileId: ID.unique(), file: InputFile.fromPath(path: image!.path.toString(), filename: User.name().toString() + '.jpg'), );```
}Rank 1: Thread
Error: AppwriteException: , File bytes must be provided for Flutter web (0)
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49 throw
packages/appwrite/src/client_browser.dart 129:7 chunkedUpload
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5 _async
packages/appwrite/src/client_browser.dart 119:33 chunkedUpload
packages/appwrite/services/storage.dart 74:30 createFile
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5 _async
packages/appwrite/services/storage.dart 52:33 createFile
packages/main/views/screens/test.dart 28:31 _getImage
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50
dart-sdk/lib/async/zone.dart 1661:54 runUnary
dart-sdk/lib/async/future_impl.dart 156:18 handleValue
dart-sdk/lib/async/future_impl.dart 840:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 869:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 641:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 715:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:15
seems like you cannot pass the path from Flutter Web
use this instead
https://pub.dev/documentation/appwrite/latest/appwrite/InputFile/InputFile.fromBytes.html
In this way you are passing bytes instead of path
XFile also has a property of getting the byte data for that file as well
https://appwrite.io/docs/products/storage/upload-download#create-file
It's also mentioned in the docs to use .fromBytes instead of fromPath in Flutter Web
Rank 1: Thread
like that?
Future _getImage() async { final ImagePicker picker = ImagePicker(); final XFile? image = await picker.pickImage(source: ImageSource.gallery);
final storage = Storage(db());
final Uint8List bytes = image?.readAsBytes() as Uint8List;
final file = await storage.createFile( bucketId: '650fe518eed83eab7514', fileId: ID.unique(), file: InputFile.fromBytes(bytes: bytes, filename: "image.jpg"),
); }```yess, but AFAIK readAsBytes() is an async Function so you might wanna await here
Rank 1: Thread
works thx
Rank 1: Thread
can you also tell me, how i can show an image from the storage without downloading it?
most of the time, you should not call toString() to solve the problem of something requiring a string. by doing that, you're probably incorrectly coercing the input
plesae make sure to format stuff like this as multiline code so it's easier to read
[SOLVED] Upload image flutter web, ios and andoid.