views:

442

answers:

2

I am trying to upload file to google sites and am obtaining the stream using apache commons file upload. I get the input stream as under

    InputStream is = fileItem.openStream();

How will I convert this input stream in file object so that below call succeeds and I am able to set the MediaFileSource to above converted file.

AttachmentEntry newAttachment = new AttachmentEntry();
newAttachment.setMediaSource(new MediaFileSource(file, fileMimeType));
+1  A: 

You have no write access to a file system on AppEngine and you're supposed to keep your data in datastore. However, gaefs project gives you a virtual file system and, as to the best pf my knowledge, supports file uploading.

Dmitry
I would prefer to upload directly from stream object, is it possible to customize the MediaFileSource in any way so that it takes *stream object
dhaval
Did you look at the code of gaefs servlet? It reads from a stream. You may also read App Engine docs: http://code.google.com/appengine/kb/java.html#fileforms
Dmitry
+1 for link to useful resource.
Carl Smotricz
+1  A: 

You could use MediaStreamSource instead of MediaFileSource.

BalusC
Thanx @BalusC , everything is working fine till I get this ServiceException that says "Not authorized to write to this feed"
dhaval
com.google.gdata.util.ServiceForbiddenException: OKNot authorized to write to this feed
dhaval