Hey,

Saving binary data to the datastore isn't too difficult - you can just
use a Blob type and ensure that you don't break the 1MB capacity of a
single entity.  You can see my class declaration below.  The "hard"
part is converting a file upload to a byte[] and then from a byte[]
back into what you would consider a "downloadable" file.  That
depends, somewhat, on your implementation.  For example, I use the
Wicket architecture and all I need to do is

FileUpload f = fileUploadField.getFileUpload();
BinaryFileData b = new BinaryFileData(f.getBytes());
pm.makePersistent(b);

I presume you are not using Wicket, but some other framework.  You'll
need to look into how it handles file uploads.

You may also find this interesting: http://code.google.com/p/gaevfs/
I haven't used it, but it skips the whole byte[] thing entirely.

Jake

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class BinaryFileData implements Serializable {

        private static final long serialVersionUID = 1L;

        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;

        @Persistent
        private String name;

        @Persistent
        private String mimeType;

        @Persistent(defaultFetchGroup="true")
        private Blob data;

        public BinaryFileData(byte[] bytes) {
                this.data = new Blob(bytes);
        }

        public byte[] getData() {
                return data.getBytes();
        }

        public void setData(byte[] d) {
                this.data = new Blob(d);
        }
}




On Mar 1, 11:25 am, Valentino Hankypants <[email protected]> wrote:
> hello together,
>
> i started working with the app engine some days ago, and now i want to
> save some binary data (pdf, etc.) from my app (eg by clicking a
> button) in the storage system.
>
> anybody who can help me doing this? (tutorials, etc.)
>
> greatz
> flo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to