【发布时间】:2014-11-21 08:34:57
【问题描述】:
我正在使用 DropZone.js
我的配置是
Dropzone.options.myAwesomeDropzone = {
url: 'UploadImages',
previewsContainer: ".dropzone-previews",
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 20,
addRemoveLinks: true,
init: function() {
this.on("success", function(file, response) {
$('.dz-progress').hide();
console.log(response);
console.log(file);
});
}
}
});
此代码与我的本地主机完美配合。
我正在将文件上传到UploadImages url。
我在该 url 方法中输入了一条运行正常的消息。
我的问题是我没有得到应该使用哪个名称来获取服务器中的内容。 就像我应该在我的服务器端实现中访问的 imageFile 变量、imageName 变量、imageContent 类型的名称。
编辑: DropZone的服务器端实现
Dropzone 不提供处理文件的服务器端实现,但上传文件的方式与简单的文件上传形式相同,如下所示:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
</form>
我知道它包括
<input type="file" name="file" />
自动在表单中
所以我们可以使用file访问它
如果
<input name="file" type="file" multiple />
然后我们可以使用file[] 访问它
在服务器端我试过了
public class ImageAction extends ActionSupport {
private List<File> file;
private List<String> fileContentType;
private List<String> fileFileName;
System.out.println("Inside Image upload ");
System.out.print("\n\n---------------------------------------\n");
int i = 0;
for (File f : file) {
System.out.print("\nFile [" + i + "] ");
System.out.print(" length: " + f.length());
System.out.print(" name:" + getFileFileName().get(i));
System.out.print(" contentType: " + getFileContentType().get(i));
i++;
}
System.out.println("\n---------------------------------------\n");
}
//getter setter
}
正在打印内图上传。
如何在 Action 类上创建文件的访问字段。
【问题讨论】:
标签: java jquery jsp struts2 dropzone.js