Created
March 2, 2016 07:03
-
-
Save codenameone/9cad1248365512416101 to your computer and use it in GitHub Desktop.
Sample code for client/server MultipartRequest usage in Codename One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MultipartRequest request = new MultipartRequest(); | |
request.setUrl(url); | |
request.addData("myFileName", fullPathToFile, "text/plain") | |
NetworkManager.getInstance().addToQueue(request); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of MultipartRequest.
From the Codename One project