Hi! :) I was wondering if it's possible to upload files to the server?
I tried this:
import http.*;
import java.util.Map;
SimpleHTTPServer server;
void setup() {
SimpleHTTPServer.useIndexHtml = false;
server = new SimpleHTTPServer(this);
TemplateFileHandler templateHandler = new ResultFromPost("index.ftl");
server.createContext("", templateHandler);
}
class ResultFromPost extends TemplateFileHandler {
public ResultFromPost(String templateFileName) {
super(templateFileName);
}
void createMap() {
Map<String, String> params = queryToMap();
println(params.get("image"));
}
}
And this is the ftl
<!DOCTYPE html>
<html>
<header></header>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" value="Upload" />
</form>
</body>
</html>
The data is there printed in the console, so that part works, but the data must be decoded. Does SimpleHTTPServer come with any helper functions for this?
A nice Example for this feature would be a tiny image gallery. Allow uploading images, and then show them as thumbnails in the html. Maybe convert them to black and white in Processing before saving them :)
Here some info about the decoding part:
https://stackoverflow.com/questions/3337056/convenient-way-to-parse-incoming-multipart-form-data-parameters-in-a-servlet
Hi! :) I was wondering if it's possible to upload files to the server?
I tried this:
And this is the ftl
The data is there printed in the console, so that part works, but the data must be decoded. Does SimpleHTTPServer come with any helper functions for this?
A nice Example for this feature would be a tiny image gallery. Allow uploading images, and then show them as thumbnails in the html. Maybe convert them to black and white in Processing before saving them :)
Here some info about the decoding part:
https://stackoverflow.com/questions/3337056/convenient-way-to-parse-incoming-multipart-form-data-parameters-in-a-servlet