这是我的代码。我无法上传任何大小超过1 mb的文件,但我已将maxFileSize设置为50mb,请帮助,我做错了什么?
@Component({
moduleId: module.id,
//define the element to be selected from the html structure.
selector: 'NeedAnalysisConsult',
//location of our template rather than writing inline templates.
templateUrl: 'need-analysis-consultation.component.html',
})
export class NeedAnalysisConsultationComponent implements OnInit {
model:any={};
consultationDate: Date;
organisation: string;
devCode:String;
maxFileSize = 50 * 1024 * 1024;
//declare a property called fileuploader and assign it to an instance of a new fileUploader.
//pass in the Url to be uploaded to, and pass the itemAlais, which would be the name of the //file input when sending the post request.
public uploader:FileUploader = new FileUploader({url: URL,isHTML5: true, itemAlias: 'consultation',maxFileSize: this.maxFileSize});
//This is the default title property created by the angular cli. Its responsible for the app works
title = 'app works!';
ngOnInit() {
//override the onAfterAddingfile property of the uploader so it doesn't authenticate with //credentials.
this.uploader.onAfterAddingFile = (file)=> { file.withCredentials = false; };
this.uploader.onBuildItemForm=(item:any,form:any)=>{
form.append('devCode',this.model.programmeCode);
form.append('date',this.model.consultationDate);
form.append('organization',this.model.organisation);
};
//overide the onCompleteItem property of the uploader so we are
//able to deal with the server response.
this.uploader.onCompleteItem = (item:any, response:any, status:any, headers:any) => {
console.log("FileUpload:successfully uploaded:", item, status, response);
if (status==201){
alert("FileUpload: successfully");
}
else {
alert("FileUpload:"+response);
}
};
}
//declare a constroctur, so we can pass in some properties to the class, which can be //accessed using the this variable
constructor(private http: Http, private el: ElementRef,private router:Router,private _location: Location) {
}
@ViewChild('selectedFile') selectedFile: any;
clear(){
this.model.programmeCode="";
this.model.organisation="";
this.model.consultationDate=null;
this.selectedFile.nativeElement.value = '';
(<HTMLInputElement>document.getElementById("file-name")).value = "";
}
updateFile(){
(<HTMLInputElement>document.getElementById("file-name")).value = "";
for(var i = 0;i<this.uploader.queue.length;i++){
if(i != 0)
(<HTMLInputElement>document.getElementById("file-name")).value += " ; "+this.uploader.queue[i].file.name;
else
(<HTMLInputElement>document.getElementById("file-name")).value = this.uploader.queue[i].file.name;
console.log(this.uploader.queue[i].file.name);
}
}
close() {
console.log("closing the window...");
this.router.navigate(['/home']);
}
removefile(){
(<HTMLInputElement>document.getElementById("file-name")).value = "";
}
backClicked() {
this._location.back();
}
}
这是我的代码。我无法上传任何大小超过1 mb的文件,但我已将maxFileSize设置为50mb,请帮助,我做错了什么?
正常的tomcat服务器应用程序不允许上载超过1 MB的文件,因此会引发错误。
如果您看到api控制台(java/. net),您将能够看到其中的错误。
可以先设置api的最大大小。使用此链接获取更多参考
如果您遇到multipart错误,请使用此链接了解更多信息。
在您的<代码>中尝试此操作。组成部分ts:
ngOnInit() {
let maxFileSize = 5 * 1024 * 1024; // modify this to your desired max file size
this.uploader = new FileUploader({
url:this.url, removeAfterUpload: false,
autoUpload: false ,
method:'post',
maxFileSize:maxFileSize
});
this.uploader.onWhenAddingFileFailed = (item, filter) => {
let message = '';
switch (filter.name) {
case 'fileSize':
message = 'Warning ! \nThe uploaded file \"' + item.name + '\" is ' + this.formatBytes(item.size) + ', this exceeds the maximum allowed size of ' + this.formatBytes(maxFileSize);
break;
default:
message = 'Error trying to upload file '+item.name;
break;
}
alert(message);
};
}
formatBytes(bytes, decimals?) {
if (bytes == 0) return '0 Bytes';
const k = 1024,
dm = decimals || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
问题内容: 我在Django应用中有一个表单,用户可以在其中上传文件。 如何设置上传文件大小的限制,以便如果用户上传的文件大于我的限制,则该表格将无效并且会引发错误? 问题答案: 此代码可能会帮助:
本文向大家介绍javascript实现限制上传文件大小,包括了javascript实现限制上传文件大小的使用技巧和注意事项,需要的朋友参考一下 前言: 项目中经常用到需要上传文件、照片等功能,同时需要限制所上传文件的大小。很多插件都会采用后台请求验证,前端Js校验比较少。本篇介绍一个前端JS便捷判断上传文件大小的方法。 这个是比较好的 下面的代码不建议使用 代码很简单,关键就是怎么用JS拿
什么是 Firebase 存储上传文件大小限制?我在网站上找不到该信息。
我使用Spring Boot,可以发送小于1MB的图像,但当我使用大于1MB的大图像发出post请求时,会出现以下错误: 下面是我尝试的所有application.properties配置: 1 2 我还研究了在web.xml文件中更改Tomcat允许的请求大小,但我没有web.xml文件。我正在使用的Tomcat绑定到应用程序中。
问题 如何限定上传文件的大小? Solution web.py 使用cgi 模块来解析用户的输入, 而 cgi 模块对最大输入大小有限制。 下面的代码限制了最大数据输入为 10MB. import cgi # Maximum input we will accept when REQUEST_METHOD is POST # 0 ==> unlimited input cgi.maxlen =