Создайте файл на GAE / J и загрузите в Google docs

Можно ли создать какой-либо файл на GAE / J и загрузить его в документы Google? Я спросил аналогичный вопрос о создании и загрузке PDF.

Спасибо.

Обновлять

Согласно Google Docs API «Чтобы загрузить документ на сервер, вы можете прикрепить файл к новому DocumentListEntry с помощью метода setFile ()». И методу setFile нужен java.io.File, который не принимается GAE / J setFile (файл java.io.File, java.lang.String mimeType). Есть ли решение, которое я могу загрузить без сохранения данных. Мне нужен тип java.io.File в качестве аргумента для работы метода setFile (). Я пробовал использовать gaevfs (http://code.google.com/p/gaevfs/)+appengine-java-io(http://code.google.com/p/appengine-java-io/), но тип File в appengine-java-io не соответствует типу File, используемому в методе setFile ().


person N. Omer Hamzaoglu    schedule 25.10.2010    source источник
comment
возможный дубликат загрузки PDF-файла файл в Google Документы, созданный pdfjet в GAE / J   -  person Nick Johnson    schedule 26.10.2010
comment
Пожалуйста, не публикуйте повторяющиеся вопросы - обновите существующий вопрос, если у вас есть дополнительные сведения.   -  person Nick Johnson    schedule 26.10.2010


Ответы (2)


Вы хотите использовать API GData для документов. Информацию о самом API можно найти здесь (в частности, часть о Загрузка документов) и эта ссылка поможет настроить его для работы в Google App Engine.

person Adrian Petrescu    schedule 25.10.2010
comment
Нет проблем с загрузкой, проблема в создании файла в GAE / J. GAE не позволяет создавать файл, поэтому я могу установить аргумент файла в Google Docs API. - person N. Omer Hamzaoglu; 26.10.2010
comment
Файлы - это просто капли данных, хранящиеся в файловой системе. Нет необходимости хранить данные в файловой системе - просто создайте их в своем приложении App Engine и загрузите напрямую. - person Nick Johnson; 26.10.2010

Благодаря Нику Джонсону я нашел способ загрузить PDF-файл на GAE / J. Я не знал о методе 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);
person N. Omer Hamzaoglu    schedule 27.10.2010