如何解决角度-如何在课程中发送上传的图片或如何将文件类型更改为Int8Array类型
我在javascript和Typescript中是相当新的。我真的需要一些帮助。我正在使用Angular 10和Spring Boot。我有一个像这样的界面:
export interface Product {
productId?: number;
sku: string;
name: string;
description: string;
unitPrice: number;
productImage: Int8Array;
active: boolean;
unitsInStock: number;
dateTimeCreated: Date;
dateTimeUpdated: Date;
}
并且即时通讯使用Angular模板驱动的表单来填充某些字段。我想在productImage:Int8Array字段中的该对象中发送Image。那就是计划。
html看起来像这样(加上其他字段的输入):
<input type="file" accept="image/*"
(change)="onFileChange($event)">
和班级:
image:File;
public onFileChange(event) {
this.image = event.target.files[0];
}
那么我该如何将image:File更改为productImage:Int8Array?还是我应该以其他方式发送它?
解决方法
看看这是否有帮助 HTML
<div class="row" style="padding:0em; margin-top: 3vh;">
<ng-container>
<input type="file" accept=".mp4,.mkv"id="file" multiple (change)="getFileDetails($event)">
<button class="btn btn-primary" (click)="uploadFiles()">Upload Video</button>
</ng-container>
TS
myFiles=[]
getFileDetails(e) {
//console.log (e.target.files);
this.myFiles=[]
for (var i = 0; i < e.target.files.length; i++) {
this.myFiles.push(e.target.files[i]);
}
}
uploadFiles()
{
const frmData = new FormData();
//you can enter other form fields here
for (var i = 0; i < this.myFiles.length; i++) {
console.log(this.myFiles[i])
frmData.append("Upload",this.myFiles[i]);
}
this.http.post('http://localhost:3000/',frmData,{responseType: 'text',reportProgress:true,observe:'events' })
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。