Skip to content

Instantly share code, notes, and snippets.

@0xRoch
Created June 6, 2011 23:04
Show Gist options
  • Save 0xRoch/1011311 to your computer and use it in GitHub Desktop.
Save 0xRoch/1011311 to your computer and use it in GitHub Desktop.
package models;
import java.lang.annotation.*;
import java.lang.reflect.Type;
import java.util.List;
import com.google.appengine.api.datastore.Blob;
import play.data.Upload;
import play.data.binding.*;
import play.mvc.Http.Request;
@Global
public class GaeBlobBinder implements TypeBinder<Blob> {
public Object bind(String string, Annotation[] antns, String value, Class type, Type type1) throws Exception {
List<Upload> uploads = (List<Upload>)Request.current().args.get("__UPLOADS");
for(Upload upload : uploads) {
if(upload.getFieldName().equals(value)) {
byte[] data = upload.asBytes();
if(data.length > 0)
return new Blob(data);
return null;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment