The first usage is parsing data in memory. The usage has high performance. We recommend it.
MultiPartDataFactory mpdf = new MemoryMultiPartDataFactory();
HttpMemoryUploadParser httpMemoryUploadParser = new HttpMemoryUploadParser(request, mpdf);
List<MultiPartFile> list = httpMemoryUploadParser.parseList();
for (MultiPartFile e : list) {
if (e.isFile()) {
e.toFile(System.getProperty("user.home" + "/" + e.getFileName());
} else {
if (e.getBytes() > 0)
System.out.println(new String(e.getContentBuffer()));
}
}
The second usage is parsing data in buffer and save data into a disk file. The usage is lower performance than the first usage. But it has lower memory cost.
DiskFileFactory dff = new DiskFileFactory(System.getProperty("user.home"));
HttpFileUploadParser parser = new HttpFileUploadParser(req, dff);
List<MultiPartFile> files = parser.parse();
optional DiskFileFactory and MultiPartDataFactory provide a several features. specify a charset,
DiskFileFactory dff = new DiskFileFactory(System.getProperty("user.home"), "utf-8");
or
MultiPartDataFactory mpdf = new MemoryMultiPartDataFactory("utf-8");
HttpFileUploadParser converts file name with utf-8 charset, also
convert the content with utf-8 charset if found the form-based uploading file
is text format. In memory appropriate, MultiPartFile object export all bytes to user. so it doesn't convert data CharSet.
DiskFileFactory dff = new DiskFileFactory(System.getProperty("user.home"), "utf-8", 0x20000);
or
MultiPartDataFactory mpdf = new MemoryMultiPartDataFactory("utf-8", 0x20000);
the code indicates the max size is 0x20000 per file.
dff.setParseThreshold(0x100000);
The code indicates the max content-length of whole requesting data.
Fastupload provides an advanced mechanism that filters uploading files. It
does not like others form-based uploading component or framework filter
feature. It filters off a boundary if found the boundary's content header
doesn't match the rules.
dff.setAllowedExtensions(".jpg, .png");
comma splitting. the code indicates HttpFileUploadParser accept two
types file. JPG and PNG.
dff.setAllowedTypes("image/jpg");
the code indicates HttpFileUploadParser accept the image/jpg
content type.
when HttpFileUploadParser filters off some boundaries, it put headers into a exceptional collection as digest information. user can get it with the API.
Set<ContentHeaderMap> exceptionals = dff.getExceptionals()
At the point, you may know MemoryMultiPartDataFactory has the same methods. indeed, it has.
mpdf.setParseThreshold(0x100000);
mpdf.setAllowedExtensions(".jpg, .png");
mpdf.setAllowedTypes("image/jpg");
Set<ContentHeaderMap> exceptionals = mpdf.getExceptionals()
you can add the dependency to your POM.xml, such that Maven resolve dependency automatically.
<dependency>
<groupId>net.sf.fastupload</groupId>
<artifactId>fastupload-core</artifactId>
<version>0.4.7</version>
</dependency>