Skip to content

A simple wrapper for Apache Commons FileUpload to use it with Netty and other IO servers

License

Notifications You must be signed in to change notification settings

javadelight/delight-fileupload

Repository files navigation

delight-fileupload

A simple wrapper for Apache Commons FileUpload for allowing it to work with Netty and other IO servers.

Part of the Java Delight Suite.

Dependency

Just add the following dependency to your projects.

<dependency>
    <groupId>org.javadelight</groupId>
    <artifactId>delight-fileupload</artifactId>
    <version>[insert latest version]</version>
</dependency>

This artifact is available on Maven Central and BinTray.

Maven Central

Please note in order to use this package, the javax.servlet dependency needs to be defined in your project as well. Such as:

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		</dependency>

Usage

First obtain the raw data of the request in the framework you are using:

byte[] data = ... posted data

String contentType = ... header "Content-Type"

Then call customized FileUpload to process the request:

FileItemIterator iterator = FileUpload.parse(data, contentType);

Finally, process the items in the multipart request:

while (iter.hasNext()) {
    FileItemStream item = iter.next();

    if (item.isFormField()) {
        ... some fields in the form
    } else {
        InputStream stream = item.openStream();
        // work with uploaded file data by processing stream ...
    }

}

About

A simple wrapper for Apache Commons FileUpload to use it with Netty and other IO servers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages