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有辅助插件吗"真是存在有辅助攻略(哔哩哔哩)一、wepoker有辅助插件吗可...
透视必备"拱趴大菠萝... 透视必备"拱趴大菠萝挂哪里"竟然是有辅助方法(哔哩哔哩)1、首先打开拱趴大菠萝挂哪里辅助器下载最新版...
透视必备"uupok... 您好,uupoker有透视吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...
透视揭露"wepok... 透视揭露"wepoker代打辅助机器人"一贯有辅助教程(哔哩哔哩)1.wepoker代打辅助机器人 ...
透视解密"hhpok... 透视解密"hhpoker软件可以玩吗"原来是有辅助脚本(哔哩哔哩)透视解密"hhpoker软件可以玩...
透视总结"aapok... 透视总结"aapoker安装包怎么使用"一直是有辅助教程(哔哩哔哩)所有人都在同一条线上,像星星一样...
透视专业"aapok... 透视专业"aapoker透视怎么用"本来是真的辅助插件(哔哩哔哩)该软件可以轻松地帮助玩家将aapo...
透视辅助"aapok... 透视辅助"aapoker脚本"本来是有辅助软件(哔哩哔哩)1、下载好aapoker脚本透视辅助下载之...
透视专业"wepok... 透视专业"wepoker私人局规律"真是真的有辅助器(哔哩哔哩)1、每一步都需要思考,不同水平的挑战...
透视解密"pokem... 透视解密"pokemmo辅助器手机版下载"切实是真的辅助方法(哔哩哔哩)1)pokemmo辅助器手机...