Created
June 6, 2011 23:04
-
-
Save 0xRoch/1011311 to your computer and use it in GitHub Desktop.
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
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