正在上传位于 Angular 项目目录中的 file/image
Uploading a file/image located in Angular Project Directory
我想上传存储在我的 angular 资产目录中的文件。下面是我用来将文件上传到 firebase 的代码。
const file = this.selectedProPic;
const filePath = `${this.uid}/propic`;
const fileRef = this.afStorage.ref(filePath);
this.taskProPic = this.afStorage.upload(filePath, file);
此处文件变量被分配了从 html 中的文件上传器 select 编辑的文件。我需要将此部分/'file' 变量修改为 select 位于 assets/img/default-avatar.jpg 的文件。我尝试使用 toPath 和 pathToFileURL 以及谷歌搜索。但是 none 他们工作了
您可以使用 Angular 的 http client:
this.http.get('assets/filename.txt', {responseType: 'text'})
.subscribe(data => {
const file = data;
const filePath = `${this.uid}/propic`;
this.afStorage.upload(filePath, file);
});
根据文件类型,您可能希望设置正确的 responseType。
我想上传存储在我的 angular 资产目录中的文件。下面是我用来将文件上传到 firebase 的代码。
const file = this.selectedProPic;
const filePath = `${this.uid}/propic`;
const fileRef = this.afStorage.ref(filePath);
this.taskProPic = this.afStorage.upload(filePath, file);
此处文件变量被分配了从 html 中的文件上传器 select 编辑的文件。我需要将此部分/'file' 变量修改为 select 位于 assets/img/default-avatar.jpg 的文件。我尝试使用 toPath 和 pathToFileURL 以及谷歌搜索。但是 none 他们工作了
您可以使用 Angular 的 http client:
this.http.get('assets/filename.txt', {responseType: 'text'})
.subscribe(data => {
const file = data;
const filePath = `${this.uid}/propic`;
this.afStorage.upload(filePath, file);
});
根据文件类型,您可能希望设置正确的 responseType。