0

公開リンクの場合は問題なく動作しますが、私の場合はローカル ディスクから画像ファイルをアップロードする必要があります。画像をbase64形式に変換し、htmlファイルをローカルディスクにも書き込みます。そのhtmlファイルは画像を表示してブラウザで開くことができますが、Googleドキュメントのドキュメントは空のファイルであり、そのhtmlファイルをGoogleにドラッグしても画像はまだありません。私のコードは以下の通りです:

DocsService client = new DocsService("testappv3");
client.setUserCredentials("username", "password");
File file = new File("c:/test.bmp");
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));

int read;
byte[] buff = new byte[1024];
while ((read = in.read(buff)) > 0)
{
    out.write(buff, 0, read);
}
out.flush();

String base64 = Base64.encode(out.toByteArray());
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
String html = "<html><body><img src=\"data:" + mimeType + ";base64," + base64 + "\"/></body></html>";


URL destFolderUrl = new URL("https://docs.google.com/feeds/default/private/full/<FOLDER_ID>/contents");
DocumentEntry newDocument = new DocumentEntry();
newDocument.setTitle(new PlainTextConstruct("test"));
newDocument.setMediaSource(new MediaByteArraySource(html.getBytes(), "text/html"));
newDocument = client.insert(destFolderUrl, newDocument);
4

1 に答える 1

0

私の経験レベルはほんの数年なので、間違っている可能性がありますが....私の理解では、あなたはもう使用できないということです

client.insert(destFolderUrl, newDocument);// but now must use ResumableGDataFileUploader


new ResumableGDataFileUploader.Builder(client, new URL(uploadLink), mediaFile, null )

うまくいけば、より多くの知識を持つ誰かが確認または否定します

于 2012-05-22T09:06:05.423 に答える