Firebase图像调整大小扩展.参照尺寸调整后的图像 [英] Firebase Image Resize Extension. Referencing the resized images
问题描述
第一次进入Firebase扩展,并觉得Image Resizer是满足我的需求的好工具.
first time jumping into the Firebase extensions and felt Image Resizer was a good one to use for my needs.
但是,使用它的文档有点麻烦,而且让我有些困惑.
However, the documentation on using it is a little thing and leaving me a bit stuck.
当前,我上传图像,它会自动生成新尺寸并将其保存到我想要的路径.但是,我无法弄清楚如何调用现在已调整大小的图像.
Currently, I upload the image, it auto generates the new dimension and saves them to my desired path. However, I am unable to figure out how to call the now resized image.
我当前正在使用这样的路径存储上传的图片;
I am currently storing the uploaded image with a path like so;
var storageRef = firebase.storage().ref("Project_Image/" + this.projectName + "/" + file.name);
,然后使用像这样的引用将原始照片作为URL;
and then getting the original photo as a url using a reference like so;
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.
This works, but the problem is I am unable to reference the newly created 600x300 resized image. Now called imagename_600x300.jpeg.
我尝试使用
.ref("Project_Image/" + this.projectName + "/" + file.name + "_600x300")
但是很明显,它捕获了"imagename.jpeg_600x300",因此返回错误/未定义.
but obviously, that grabs "imagename.jpeg_600x300" and, therefor returns an error/undefined.
我不确定是否有更好的方法来初始存储这些文件以帮助检索,或者是否有明显的答案.
I am not sure if there is a better way to initially store these files that would help with retrieving, or if there is an obvious answer.
谢谢!
推荐答案
听起来您需要剥离扩展名并将其放在前缀之后.这样的事情应该起作用:
It sounds like you need to strip off the extension and put it after the prefix. Something like this should work:
function resizedName(fileName, dimensions = '600x300') {
const extIndex = fileName.lastIndexOf('.');
const ext = fileName.substring(extIndex);
return `${fileName.substring(0, extIndex)}_${dimensions}${ext}`;
}
这篇关于Firebase图像调整大小扩展.参照尺寸调整后的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!