views:

27

answers:

1

Hi,

I need to upload a PDF file to users google docs which is generated by pdfjet on google app engine. I figure out to generate pdf using pdfjet for gae/j. pdfjet uses streams to create the pdf. Is there anyway to convert stream to file so I can upload to users google docs. I tried gaevfs but couldn't make it work. I can use another pdf generation solution if needed or another virtual file system etc.

PDF generation code

ByteArrayOutputStream os = new ByteArrayOutputStream();
PDF pdf = new PDF(os);

Google Docs API code

DocumentListEntry newEntry = new PdfEntry();
newEntry.setTitle(new PlainTextConstruct("Some Report"));

The line I couldn't get make it work : setFile(File, String)

newEntry.setFile(pdf, "application/pdf");

Thanks.

A: 

Couldn't you simply write from ByteArrayOutputStream to FileOutputStream using the ByteArrayOutputStream.writeTo(OutputStream) method? Like this:

ByteArrayOutputStream os = new ByteArrayOutputStream();
PDF pdf = new PDF(os);  
FileOutputStream fos = new FileOutputStream("myPDF.pdf");
baos.writeTo(os);
Frozen Spider
I tried that but java.io.FileOutputStream is not supported by Google App Engine's Java runtime environment. I tried to use GaeVfs(http://code.google.com/p/gaevfs/) but I couldn't make it work. As far as I know it creates files in memcache which I could create a pdf in memcache then send it to google docs but I was unable to make it work too. I'm getting "can't accept class com.newatlanta.commons.vfs.provider.gae.GaeFileName as a memcache entity" exception.
N. Omer Hamzaoglu