Java 在GAE/J上创建文件并上传到Google文档

Java 在GAE/J上创建文件并上传到Google文档,java,google-app-engine,google-docs-api,Java,Google App Engine,Google Docs Api,可以在GAE/J上创建任何类型的文件并上传到谷歌文档吗?我以前问过一个关于创建和上传PDF的问题 谢谢 更新 根据Google Docs API,“要将文档上载到服务器,可以使用setFile()方法将文件附加到新的DocumentListEntry。”。而setFile方法需要java.io.File,而GAE/J setFile不接受该文件(java.io.File文件,java.lang.String mimeType)。是否有一种解决方案可以在不存储数据的情况下上传。我需要java.io

可以在GAE/J上创建任何类型的文件并上传到谷歌文档吗?我以前问过一个关于创建和上传PDF的问题

谢谢

更新


根据Google Docs API,“要将文档上载到服务器,可以使用setFile()方法将文件附加到新的DocumentListEntry。”。而setFile方法需要java.io.File,而GAE/J setFile不接受该文件(java.io.File文件,java.lang.String mimeType)。是否有一种解决方案可以在不存储数据的情况下上传。我需要java.io.File type作为setFile()方法工作的参数。我尝试过使用gaevfs(但appengine java io中的类型文件与setFile()方法中使用的类型文件不匹配。

您想在文档中使用GData API。您可以找到有关API本身的信息(特别是关于,并将有助于将其设置为在Google App Engine中工作。

多亏了Nick Johnson,我找到了在GAE/J上上传PDF的方法。我不知道setMediaSource()方法对于PdfEntry。至少是示例,也不是我找到的任何代码。我尝试了几乎每个示例,解决方案,但最后我在寻找其他代码时找到了另一个代码。如果其他人需要它,答案如下。大部分代码是PDF生成,它取自pdfjet的示例,感谢大家的帮助

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PDF pdf = new PDF(os);
        Font f1 = new Font(pdf, "Helvetica");
        Font f2 = new Font(pdf, "Helvetica-Bold");
        Font f3 = new Font(pdf, "Helvetica-Bold");
        pdf.setTitle("Using TextColumn and Paragraph classes");
        pdf.setSubject("Examples");
        pdf.setAuthor("Innovatics Inc.");
        Page page = new Page(pdf, Letter.PORTRAIT);
        f1.setSize(12);
        f2.setSize(16);
        f3.setSize(14);
        TextColumn column = new TextColumn(f1);
        Paragraph p1 = new Paragraph();
        p1.setAlignment(Align.CENTER);
        p1.add(new TextLine(f2, "Switzerland"));
        Paragraph p2 = new Paragraph();
        p2.add(new TextLine(f2, "Introduction"));
        Paragraph p3 = new Paragraph();
        p3.setAlignment(Align.JUSTIFY);
        TextLine text = new TextLine(f2);
        text.setText("The Swiss Confederation was founded in 1291 as a defensive alliance among three cantons. In succeeding years, other localities joined the original three. The Swiss Confederation secured its independence from the Holy Roman Empire in 1499. Switzerland's sovereignty and neutrality have long been honored by the major European powers, and the country was not involved in either of the two World Wars. The political and economic integration of Europe over the past half century, as well as Switzerland's role in many UN and international organizations, has strengthened Switzerland's ties with its neighbors. However, the country did not officially become a UN member until 2002. Switzerland remains active in many UN and international organizations but retains a strong commitment to neutrality.");
        text.setFont(f1);
        p3.add(text);
        Paragraph p4 = new Paragraph();
        p4.add(new TextLine(f3, "Economy"));
        Paragraph p5 = new Paragraph();
        p5.setAlignment(Align.JUSTIFY);
        text = new TextLine(f1);
        text.setText("Switzerland is a peaceful, prosperous, and stable modern market economy with low unemployment, a highly skilled labor force, and a per capita GDP larger than that of the big Western European economies. The Swiss in recent years have brought their economic practices largely into conformity with the EU's to enhance their international competitiveness. Switzerland remains a safehaven for investors, because it has maintained a degree of bank secrecy and has kept up the franc's long-term external value. Reflecting the anemic economic conditions of Europe, GDP growth stagnated during the 2001-03 period, improved during 2004-05 to 1.8% annually and to 2.9% in 2006. Even so, unemployment has remained at less than half the EU average.");
        p5.add(text);
        Paragraph p6 = new Paragraph();
        p6.setAlignment(Align.RIGHT);
        text = new TextLine(f1);
        text.setColor(RGB.BLUE);
        text.setText("Source: The world fact book.");
        text.setURIAction("https://www.cia.gov/library/publications/the-world-factbook/geos/sz.html");
        p6.add(text);
        column.addParagraph(p1);
        column.addParagraph(p2);
        column.addParagraph(p3);
        column.addParagraph(p4);
        column.addParagraph(p5);
        column.addParagraph(p6);
        column.setPosition(90, 300);
        column.setSize(470, 100);
        column.drawOn(page);
        pdf.flush();
        docsService.setOAuthCredentials(getOAuthParams(), new OAuthHmacSha1Signer());
        URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full/"+folderID+"/contents?xoauth_requestor_id="+user.getEmail());
        PdfEntry newDocument = new PdfEntry();
        newDocument.setCanEdit(true); 
        newDocument.setTitle(new PlainTextConstruct("Sample Report"));
        newDocument.setMediaSource(new MediaByteArraySource(os.toByteArray(), "application/pdf"));
        docsService.insert(feedUrl, newDocument);

上传没有问题,问题是在GAE/J中创建一个文件。GAE不允许创建文件,因此我可以在Google Docs API中设置文件参数。文件只是存储在文件系统中的数据块。不需要将数据存储在文件系统中,只需在应用程序引擎应用程序中创建数据,然后直接上传即可。可能重复of请不要发布重复的问题-如果您有更多详细信息,请更新您现有的问题。