Skip to content

Instantly share code, notes, and snippets.

@lstoll
Created May 9, 2010 19:27
Show Gist options
  • Save lstoll/395351 to your computer and use it in GitHub Desktop.
Save lstoll/395351 to your computer and use it in GitHub Desktop.
package controllers;
import java.io.*;
import java.util.Map;
import play.Logger;
import play.mvc.*;
public class Application extends Controller {
public static void index() {
render();
}
public static void upload(File myFile) {
// NO GOOD
//play.Logger.debug(body);
for (Map.Entry e : params.allSimple().entrySet()) {
Logger.debug("param key: " + e.getKey() + ", value: " + e.getValue());
}
if (myFile != null)
Logger.debug("File name: " + myFile.getName());
else
Logger.debug("No file.");
InputStream is = request.body;
for (Map.Entry<String, Http.Header> e : request.headers.entrySet()) {
Logger.debug("Header key: " + e.getKey() + ", value:" +e.getValue().value());
}
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
is.close();
}
catch (IOException ioe) {
}
Logger.debug("Body" + sb.toString());
}
public static void send(String blobid) {
response.setHeader("X-AppEngine-BlobKey", blobid);
// Can also set Content-Type and Content-Disposition
}
}
#{extends 'main.html' /}
#{set title:'Home' /}
<h1>Hello ${session.get("user")}</h1>
<body>
<form action="${com.google.appengine.api.blobstore.BlobstoreServiceFactory.getBlobstoreService().createUploadUrl("/Application/upload")}" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>
</body>
05-09 12:23PM 02.689 /Application/upload 200 111ms 194cpu_ms 0kb Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.29 Safari/533.4,gzip(gfe)
D 05-09 12:23PM 02.780 play.Logger debug: param key: action, value: upload
D 05-09 12:23PM 02.781 play.Logger debug: param key: controller, value: Application
D 05-09 12:23PM 02.781 play.Logger debug: No file.
D 05-09 12:23PM 02.786 play.Logger debug: Header key: content-type, value:multipart/form-data; boundary=000e0cd14f549403fd04862e386d
D 05-09 12:23PM 02.786 play.Logger debug: Header key: accept-language, value:en-US,en;q=0.8
D 05-09 12:23PM 02.786 play.Logger debug: Header key: host, value:twitter-chat.appspot.com
D 05-09 12:23PM 02.786 play.Logger debug: Header key: x-appengine-blobchunksize, value:2843
D 05-09 12:23PM 02.786 play.Logger debug: Header key: accept, value:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
D 05-09 12:23PM 02.786 play.Logger debug: Header key: origin, value:http://twitter-chat.appspot.com
D 05-09 12:23PM 02.787 play.Logger debug: Header key: user-agent, value:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome
D 05-09 12:23PM 02.787 play.Logger debug: Header key: accept-charset, value:ISO-8859-1,utf-8;q=0.7,*;q=0.3
D 05-09 12:23PM 02.787 play.Logger debug: Header key: cache-control, value:max-age=0
D 05-09 12:23PM 02.787 play.Logger debug: Header key: cookie, value:__utmz=218330182.1273086023.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=218330182.147324625
D 05-09 12:23PM 02.787 play.Logger debug: Header key: x-appengine-blobsize, value:2843
D 05-09 12:23PM 02.787 play.Logger debug: Header key: referer, value:http://twitter-chat.appspot.com/
D 05-09 12:23PM 02.788 play.Logger debug: Header key: x-appengine-blobupload, value:true
D 05-09 12:23PM 02.788 play.Logger debug: Body
W 05-09 12:23PM 02.799 Invalid HTTP response code (200) for Blob upload. Valid codes are 301, 302, and 303.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment