[gwtupload] Example of using new GAE libs

Showing 1-4 of 4 messages
[gwtupload] Example of using new GAE libs wesn 5/19/10 12:20 PM

Please could you include a code sample of how to use your new GAE
libraries. It would be the most rockingest if you could include a
multipart example too.


[gwtupload] Re: Example of using new GAE libs dindeman 5/20/10 8:58 AM
I recently started using Manuel's library to upload images onto the
GAE datastore.
Here is the way I extended the AppEngineUploadAction servlet to do so
(pay attention at replacing <you_package_name_here> with your own
servlet's package name):

package <your_package_name_here>;

import gwtupload.server.exceptions.UploadActionException;
import gwtupload.server.gae.AppEngineUploadAction;

import java.io.InputStream;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.IOUtils;

import com.google.appengine.api.datastore.Blob;

public class DatastoreUploadAction extends AppEngineUploadAction {

        public String executeAction(HttpServletRequest request,
List<FileItem> sessionFiles) throws UploadActionException {
                String out = super.executeAction(request, sessionFiles);

                for(FileItem imgItem : sessionFiles) {
                        PersistenceManager pm = ContentServiceImpl.getPersistenceManager();
                        Transaction tx = pm.currentTransaction();
                        try {
                            // Start the transaction

                            InputStream imgStream = imgItem.getInputStream();
                                Blob blob = new Blob(IOUtils.toByteArray(imgStream));
                                ImageBlob imageBlob = new ImageBlob(imgItem.getName(), blob);


                            // Commit the transaction, flushing the object to the datastore
                        catch(Exception e) {
                        finally {
                            if(tx.isActive()) {
            return out;

And of course don't forget to map the servlet in web.xml:


I hope this helps.
Re: [gwtupload] Re: Example of using new GAE libs Michael Witt 5/27/11 6:48 PM
That was quite helpful ... thanks!
Re: [gwtupload] Re: Example of using new GAE libs Juan Manuel Vicente 4/2/12 5:33 PM
Can you attach ImageBlob code?