Angular上传视频文件后video_url不显示文件
创始人
2024-10-29 10:00:44
0

在组件中增加以下代码:

import { Component, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
fileData: File = null;
@ViewChild(NgForm) form: NgForm;
constructor(private http: HttpClient) { }
onFileSelect(event) {
if (event.target.files.length > 0) {
const file = event.target.files[0];
this.fileData = file;
}
}
onSubmit() {
const formData = new FormData();
formData.append('file', this.fileData);
this.http.post('/api/upload', formData)
.subscribe(res => {
console.log(res);
this.form.reset();
});
}
}

另外,需要在上传文件的API中,添加Content-Disposition头部,如下所示:

Content-Disposition: attachment;filename="your_file_name.jpg"

这样就可以成功上传视频文件,并且video_url将会正确显示文件。

相关内容

热门资讯

透视工具"wepok... 透视工具"wepoker有没有挂"sohoopoker辅助(其实是真的辅助工具)-哔哩哔哩1、下载好...
透视有挂"pokem... 透视有挂"pokemmo修改器手机版"wpk辅助是什么(本来有辅助下载)-哔哩哔哩1、点击下载安装,...
为了进一步"竞技联盟... 为了进一步"竞技联盟辅助"hhpoker到底可以作必弊码(一直存在有辅助下载)-哔哩哔哩1、在hhp...
透视真的"wepok... 透视真的"wepoker轻量版辅助"德普之星怎么开辅助(一贯真的有辅助app)-哔哩哔哩1、金币登录...
透视有挂"werpl... 透视有挂"werplan外开挂"epoker免费透视脚本(竟然真的是有辅助工具)-哔哩哔哩epoke...
透视讲解"hhpok... 透视讲解"hhpoker辅助器视频"哈糖大菠萝怎么开挂(果然真的是有辅助平台)-哔哩哔哩1、金币登录...
截至发稿"wepok... 截至发稿"wepoker破解游戏盒子"wepoker脚本(果然是真的辅助app)-哔哩哔哩所有人都在...
于此同时"poker... 于此同时"poker辅助器免费安装"aapoker安装包怎么使用(确实存在有辅助插件)-哔哩哔哩1、...
透视有挂"竞技联盟辅... 透视有挂"竞技联盟辅助"wepoker怎么看底牌(本来真的有辅助下载)-哔哩哔哩1、wepoker怎...
此事引发广泛关注"w... 此事引发广泛关注"wepoker软件辅助程序"we-poker是什么软件(一贯有辅助平台)-哔哩哔哩...