[英]How to know the file count when uploading via multipart form-data in java
I am trying to upload multiple files using multipart form-data in java and I am using play framework. 我正在尝试使用Java中的多部分表单数据上传多个文件,并且正在使用播放框架。
Http.MultipartFormData body = request().body().asMultipartFormData(); files=body.getFiles();
But I may have more than 1 file and I need to know the count of files in body. 但是我可能有多个文件,并且我需要知道正文中文件的数量。
I got the file count using a for loop. 我使用for循环获得了文件计数。
But Is there a better way to get the file count without using a loop. 但是有没有更好的方法来获取文件计数而不使用循环。
Http.MultipartFormData body = request().body().asMultipartFormData();
List<Http.MultipartFormData.FilePart> files = body.getFiles();
int fileCount = files.size();
Here fileCount will give you number of files you have. 在这里,fileCount将为您提供您拥有的文件数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.