The `Rest` API doesn't support multipart file upload. You would need to use the `MultipartRequest` class e.g.:
MultipartRequest request = new MultipartRequest();
request.setUrl(url);
request.addData("myFileName", fullPathToFile, "text/plain")
NetworkManager.getInstance().addToQueue(request);
See this for further details: https://www.codenameone.com/javadoc/com/codename1/io/MultipartRequest.html
[Codename One][1] has a builtin standard upload API thru support for the multipart request HTTP standard in [MultipartRequest][2].
[MultipartRequest][2] seamlessly handles the binary base64 etc.
MultipartRequest request = new MultipartRequest();
request.setUrl(url);
request.addData("myFileName", fullPathToFile, "text/plain")
NetworkManager.getInstance().addToQueue(request);
Java servlet code to intercept this should look like that:
@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
}
}
}
I'm not a PHP guy but a quick google search landed me on [w3c school][3] with this
<!-- language: php -->
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
[1]: https://www.codenameone.com/
[2]: https://www.codenameone.com/javadoc/com/codename1/io/MultipartRequest.html
[3]: http://www.w3schools.com/php/php_file_upload.asp