I'm unable to retrieve the resized images from Firebase. I get the error: 'Unhandled Exception: [firebase_storage/object-not-found] No object exists at the desired reference.'
I am able to successfully upload my image files to firebase storage with the below function.
Future<String> uploadResizedData(String image, Uint8List data) async {
//UPLOADS IMAGES TO FIREBASE STORAGE BUCKET WITH IMAGE RESIZE EXTENSION INSTALLED
final storage = FirebaseStorage.instanceFor(bucket: 'resized');
final storageRef = storage.ref().child(image);
final metadata = SettableMetadata(contentType: mime(image));
final result = await storageRef.putData(data, metadata);
//ATTEMPS TO FETCH RESIZED IMAGE
if (result.state == TaskState.success) {
final resizedImagePath =
'${path.basenameWithoutExtension(image)}_200x200.jpeg';
final resizedImageRef = storage.ref(resizedImagePath);
final resizedImageDownloadURL = await resizedImageRef.getDownloadURL();
return resizedImageDownloadURL;
} else {
return null;
}
}
I use a separate storage bucket for resized images called 'resized'. It uploads the images and resizes them to have dimensions of 200x200. This is all happening as expected, as I can see the resized images in my firebase storage bucket. However, I haven't been able to figure out how to access and download these images.
In the second half of the function:
if (result.state == TaskState.success) {
final resizedImagePath =
'${path.basenameWithoutExtension(image)}_200x200.jpeg';
final resizedImageRef = storage.ref(resizedImagePath);
final resizedImageDownloadURL = await resizedImageRef.getDownloadURL();
return resizedImageDownloadURL;
} else {
return null;
}
I take the path of the originally uploaded image
, and then get the part of path after the last separator, and without any trailing file extension (using path.basenameWithoutExtension
). This allows me to add _200x200.jpeg
to the end of the image to ensure I'm getting the correctly resized image.
I use the same storage reference as the originally uploaded image and try to fetch this resized image's download url.
I'm left with this error: Unhandled Exception: [firebase_storage/object-not-found\] No object exists at the desired reference.
It might have to do with requiring access to a new access token for the resized images, but I've been unable to figure out how to access that either.
Any help is appreciated!
Resize-image extension: https://extensions.dev/extensions/firebase/storage-resize-images