我有以下代码用于上传文件,似乎可以在我的本地(任何文件大小)上工作,但是当我将其指向我的文件大于15MB的azure web app服务时,它不起作用。
这就是我的要求:
Accept:application/json, text/plain, */*
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryBBKpQY4MP4j1noAY
Origin:http://xxxxxxxxx.azurewebsites.net
Referer:http://xxxxxxxxxxx.azurewebsites.net/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
------WebKitFormBoundaryBBKpQY4MP4j1noAY
Content-Disposition: form-data; name="selectFile"; filename="JDGUPLOAD - date error.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
<div class="customfile-container">
<input type="file" id="selectFile" name="selectFile" class="custom-file-input" multiple />
</div>
public uploadFile() {
let files = this.elem.nativeElement.querySelector('#selectFile').files;
if (files.length == 0) {
this.nofileattached = true;
this.nofileattached = true;
//wait 3 Seconds and hide
setTimeout(function () {
this.nofileattached = false;
console.log(this.nofileattached);
}.bind(this), 5000);
}
else {
this.loading = true;
debugger;
let formData = new FormData();
let file = files[0];
formData.append('selectFile', file, file.name);
this.fileUploader.uploadCustomerFile(formData, this.customerid, this.overrideData, this.username).subscribe(res => this.importComplete(res));
}
}
uploadCustomerFile(formData: FormData, customerid, overrideData, username) {
let _url: string = this.config.apiUrl + '/api/FileExtract/ExtractFile?param=' + customerid + '-' + overrideData + '-' + username + '';
return this._http.post(_url, formData).map((res: Response) => res.json());
}
答案 0 :(得分:0)
在Azure App Service中,您可以通过在web.config
文件中设置<requestLimits>
来增加文件上传大小限制:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
<!--Byte in size,increase it to 2GB-->
</requestFiltering>
</security>
</system.webServer>
对于ASP.NET,以及添加maxAllowedContentLength
设置,您还需要添加:
<system.web>
<httpRuntime maxRequestLength="2097152" />
<!--KB in size, 4MB by default, increase it to 2GB-->
</system.web>
如果您使用的是PHP,则还需要在.user.ini
目录中创建一个名为/wwwroot
的文件,并在其中添加upload_max_filesize
和post_max_size
的值:
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M