对于我的 vue 应用程序中的注册模块,我让用户以表单的形式上传图像。我将这些图像上传到我的存储中,并将这张照片的下载 url 保存在注册中。编辑注册时,我需要从存储中取出照片,这很简单,因为我得到了 url。但我需要它是一个 file() 对象。我找到了将它变成 blob 的方法,但它需要是一个文件。我怎样才能做到这一点?
最佳答案
它可以通过请求一个 blob 并生成一个 File 对象来完成。有必要指定 blob 的 MIME 类型。
const urlToObject= async()=> {
const response = await fetch(image);
// here image is url/location of image
const blob = await response.blob();
const file = new File([blob], 'image.jpg', {type: blob.type});
console.log(file);
}
关于javascript - 使用 js 到 file() 对象的图像 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54983591/