Skip to content

Instantly share code, notes, and snippets.

@codenameone
Created March 2, 2016 07:03
Show Gist options
  • Save codenameone/9cad1248365512416101 to your computer and use it in GitHub Desktop.
Save codenameone/9cad1248365512416101 to your computer and use it in GitHub Desktop.
Sample code for client/server MultipartRequest usage in Codename One
MultipartRequest request = new MultipartRequest();
request.setUrl(url);
request.addData("myFileName", fullPathToFile, "text/plain")
NetworkManager.getInstance().addToQueue(request);
@WebServlet(name = "UploadServlet", urlPatterns = {"/upload"})
@MultipartConfig(fileSizeThreshold = 1024 * 1024 * 100, // 10 MB
maxFileSize = 1024 * 1024 * 150, // 50 MB
maxRequestSize = 1024 * 1024 * 200) // 100 MB
public class UploadServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Collection<Part> parts = req.getParts();
Part data = parts.iterator().next();
try(InputStream is = data.getInputStream()) {}
// store or do something with the input stream
}
}
}
@codenameone
Copy link
Author

Sample usage of MultipartRequest.

From the Codename One project

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