Firebase 图片调整大小扩展.引用调整大小的图像



第一次跳入Firebase扩展程序,感觉图像调整器是一个很好的使用,可以满足我的需求。

但是,关于使用它的文档是一件小事,让我有点卡住了。

目前,我上传图像,它会自动生成新尺寸并将它们保存到我想要的路径。但是,我无法弄清楚如何调用现在调整大小的图像。

我目前正在使用这样的路径存储上传的图像;

var storageRef = firebase.storage().ref("Project_Image/" + this.projectName + "/" + file.name);

然后使用这样的引用将原始照片作为 URL 获取;

firebase.storage()
.ref("Project_Image/" + this.projectName + "/" + file.name).getDownloadURL()
.then((url) => {
this.imageURL = url;
// eslint-disable-next-line no-console
console.log("Getting Image " + this.imageURL);
})

这有效,但问题是我无法引用新创建的 600x300 调整大小的图像。现在称为imagename_600x300.jpeg。

我试过使用

.ref("Project_Image/" + this.projectName + "/" + file.name + "_600x300")

但显然,这会抓取"imagename.jpeg_600x300",从而返回错误/未定义。

我不确定是否有更好的方法来最初存储这些文件,以帮助检索,或者是否有明显的答案。

谢谢!

听起来你需要去掉扩展名并将其放在前缀之后。这样的事情应该有效:

function resizedName(fileName, dimensions = '600x300') {
const extIndex = fileName.lastIndexOf('.');
const ext = fileName.substring(extIndex);
return `${fileName.substring(0, extIndex)}_${dimensions}${ext}`;
}

最新更新