开发者

Grails AppEngine file upload using GAEVFS

I'm working on Grails web application and need to upload files. I have a form (simplified here):

<g:form action="save" method="post"  enctype="multipart/form-data">           
<input type="file" id="image" name="image" />                                
<input class="save" type="submit" value="Create" />
</g:form>

and in Controller code (I know that this should not be in controller but this is just to make it work and than will be designed better):

def save = {
 GaeVFS.setRootPath( servletContext.getRealPath( "/" ) );
 FileSystemManager fsManager = GaeVFS.getManager();
 FileObject tmpFolder = fsManager.resolveFile( "gae://WEB-INF/upload_files" );
 if ( !tmpFolder.exists() ) {
  tmpFolder.createFolder();
 }

 //I NEED CODE HERE TO SAVE THE IMAGE IN THE BIGTABLE VIA GAEVFS
}

So I have two problems:

A. When save create button is pressed a get exception since it tries to use Apache Commons FileUpload that tries to save to file system.

How do I disable it?

Exception is: java.lang.NoClassDefFoundError: java.rmi.server.UID is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51) at org.apache.commons.fileupload.disk.DiskFileItem.开发者_JAVA百科(DiskFileItem.java:103) at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)

B. I need the code example to save image via gaevfs I have seen example in GaeVfsServlet but I still don't know how exactly it should look in my case. Any kind of help is welcome.

GaeVfsServlet url: http://code.google.com/p/gaevfs/source/browse/trunk/src/com/newatlanta/appengine/servlet/GaeVfsServlet.java


I came across the very same problem and I am using a grails plugin called ajaxuploader to get around the issue - the file that gets uploaded is available to your controller as an inputstream object and doesnt have to use the commons file upload API at all.

http://www.grails.org/plugin/ajax-uploader

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜