最近引入的Firebase扩展“图像调整大小”在将图片上传到存储桶后会生成缩略图。
扩展程序完成后,如何获取此缩略图图像的下载网址?
final StorageReference storageRef =
FirebaseStorage.instance.ref().child(fileName);
final StorageUploadTask uploadTask = storageRef.putFile(
File(path),
);
final StorageTaskSnapshot downloadUrl = (await uploadTask.onComplete);
final String url = (await downloadUrl.ref.getDownloadURL()); //This will give me the download url of file before resize
// ??How do I the download url of resized image that gets stored in fileName/thumbnails folder
答案 0 :(得分:-1)
将图像文件上传到指定的Cloud Storage bucket
时,此扩展名:
例如,如果您在此处指定一个拇指路径,然后将图像上传到 /images/original.jpg ,则调整大小后的图像将存储在 / images / thumbs / original_200x200 .jpg
因此,文件的网址将是-
String name = url.substring(url.lastIndexOf("/")+1,url.indexOf("."));
String urlStr = "thumbnails/"+name+"_"+width+"x"+height+url.substring(url.indexOf("."),url.length());
storageRef.child(url.replace(name,urlStr)).getDownloadUrl()
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
}})