Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created March 31, 2010 04:29
Show Gist options
  • Save LeifW/349935 to your computer and use it in GitHub Desktop.
Save LeifW/349935 to your computer and use it in GitHub Desktop.
import javax.servlet.http.*;
import javax.servlet.ServletOutputStream;
import java.io.InputStream;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class ExampleServlet extends HttpServlet {
ServletFileUpload upload;
public void init() {
this.upload = new ServletFileUpload();
}
doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
FileItemIterator iter = null;
FileItemStream item = null;
try {
iter = upload.getItemIterator(req);
} catch (FileUploadException fue) {
fue.printStackTrace();
}
try {
item = iter.next();
} catch (FileUploadException fue) {
fue.printStackTrace();
}
InputStream in = item.openStream();
}
}
@LeifW
Copy link
Author

LeifW commented Mar 31, 2010

Example of using Apache Commons FileUpload
http://commons.apache.org/fileupload/using.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment