我正在将文件上传到s3存储桶。而上载时需要找到文件扩展名,并需要添加正确的内容类型。
$('#upload-files').on('click', function(e) {
e.preventDefault();
var fileName = data.files[0].name;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if (ext == "pdf") {
console.log(data);
data.submit();
} else {
alert("Upload Pdf images only");
return false;
}
})
如何在上传之前添加其内容类型。
答案 0 :(得分:0)
此代码将帮助您将数据发送到服务器:
public formdata = new FormData();
onSubmit() {
this.resetform(); //Order matters here
let headers: any = new Headers();
headers.append('Content-type', 'undefined');
formData.append("selectFile", this.formData);
const req5 = new HttpRequest('POST', 'url as hosted on TOMCAT', formData,
reportProgress: true,
responseType: 'text'
});
return this.httpClient.request(req5).subscribe(e => {
(console.log(e);)
}
}
resetform() {
this.formData = new FormData();
}