一旦图片上传到存储桶,最近推出的 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
最佳答案
当您将图像文件上传到您指定的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'
}})
关于android - firebase调整图像扩展完成后如何获取缩略图的下载网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58247615/