2

我正在开发一个基于 Web 的应用程序,它允许用户使用 GData Java API 将 Word 文档上传到 Google Docs。

(我遇到了这个博客,在那里我发现我实际上可以使用字节数组来上传文档而不是使用文件

我正在使用 Netbeans + JDK 1.6

我的servlet中的相关代码:

DocsService docsService = new DocsService("care.udhc.co.in");                
try {
    docsService.setUserCredentials("sbose78@gmail.com", "*******");      

    DocumentListEntry newDocument = new DocumentListEntry();

    String s="hello bose";
    byte byteData[]=s.getBytes();

    // Load the byte array into a MediaSource
    MediaByteArraySource mediaSource = new MediaByteArraySource(byteData, MediaType.fromFileName("bose.doc").getMimeType());
    MediaContent content = new MediaContent();
    content.setMediaSource(mediaSource);
    content.setMimeType(new ContentType(mediaSource.getContentType()));
    newDocument.setContent(content);

    String gdocsFilename = new String("My Filename");
    newDocument.setTitle(new PlainTextConstruct(gdocsFilename));
    out.println("OK");
    // Push it into Google Docs!! 
    DocumentListEntry uploadedRef = docsService.insert(new URL("https://docs.google.com/feeds/default/private/full/"), newDocument);
} catch(Exception e) {
   out.println(e.toString());
} finally {            
    out.close();
}

当我在本地运行它时,遇到以下错误:

com.google.gdata.util.InvalidEntryException: We're sorry, a server error occurred. Please try again. GDataInvalidEntryExceptionWe're sorry, a server error occurred. Please try again.

当我运行部署在 Internet ( Jelastic cloud ) 上的版本时,我得到了这个:

java.lang.NoClassDefFoundError: com/google/gdata/data/extensions/QuotaBytesTotal
com.google.gdata.data.docs.MetadataEntry.declareExtensions(MetadataEntry.java:86)
com.google.gdata.data.ExtensionProfile.addDeclarations(ExtensionProfile.java:71)
com.google.gdata.data.BaseFeed.declareExtensions(BaseFeed.java:235)
com.google.gdata.client.docs.DocsService.declareExtensions(DocsService.java:171)
com.google.gdata.client.docs.DocsService.<init>(DocsService.java:108)
bose.google.UploadToDocs.processRequest(UploadToDocs.java:30)
bose.google.UploadToDocs.doGet(UploadToDocs.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

请给我一个解决方法?

4

1 回答 1

0

您似乎缺少所需的依赖项之一,可能是 gdata-core-1.0.jar。

此外,请检查此页面以获取外部依赖项:https ://developers.google.com/gdata/articles/java_client_lib

于 2012-06-05T00:56:50.010 回答