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将会正确显示文件。

相关内容

热门资讯

重要通知!aapoker脚本怎... 重要通知!aapoker脚本怎么用(辅助挂)果然真的有挂(有挂分享)1、aapoker脚本怎么用模拟...
玩家交流!hh poker辅助... 玩家交流!hh poker辅助有用吗(辅助挂)竟然存在有挂(确实有挂)hh poker辅助有用吗透视...
教程攻略!德州透视竞技联盟(辅... 教程攻略!德州透视竞技联盟(辅助挂)其实是有挂(有挂工具)1、打开软件启动之后找到中间准星的标志长按...
分享认知!hhpoker有辅助... 分享认知!hhpoker有辅助吗(辅助挂)真是是有挂(存在有挂)1、超多福利:超高返利,海量正版游戏...
科普分享!pokemmo脚本(... 科普分享!pokemmo脚本(辅助挂)一贯是真的有挂(发现有挂)1、pokemmo脚本公共底牌简单,...
一分钟带你了解!WePoKer... 一分钟带你了解!WePoKer辅助器(辅助挂)切实存在有挂(有挂方法)1、WePoKer辅助器脚本辅...
揭秘关于!黑侠破解wepoke... 揭秘关于!黑侠破解wepoker(辅助挂)原来是真的有挂(了解有挂)1、揭秘关于!黑侠破解wepok...
避坑细节!hh poker辅助... 避坑细节!hh poker辅助器先试用(辅助挂)果然是真的有挂(有挂秘笈)1、hh poker辅助器...
发现一款!佛手在线有挂吗(辅助... 您好,佛手在线有挂吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家...
来一盘!wepoker怎么提高... 来一盘!wepoker怎么提高运气(辅助挂)本来是真的有挂(有人有挂)1、wepoker怎么提高运气...