
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?

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

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?

ah bruh

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'),
);```
}

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 <fn> 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 <fn>

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

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


works thx

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.
Recommended threads
- Privacy settings for storage
In my app the user could upload sensitive images for themselves (as a weight loss journal) and they probably don’t want developers or anyone else but themselves...
- Corrupted files on AWS S3
Hello! I'm having trouble using S3 storage with appwrite for file uploads. It happens when uploading files from the Javascript SDK or from the console. The fi...
- Stuck in Readonly Mode After Pro Subscri...
Hello team, I really need some urgent help. I recently resubscribed to the Pro plan hoping to get back into a project I created a while ago, but I'm still unab...
