【问题标题】:save byte[] to Google Drive from AppEngine Java从 AppEngine Java 将 byte[] 保存到 Google Drive
【发布时间】:2012-07-14 18:11:29
【问题描述】:
byte[] fileItemData = blobstoreService.fetchData(blobKey, 0, 999999);   
ByteArrayContent mediaContent = new ByteArrayContent(fileItemMimeType, fileItemData);
insert = driveService.files().insert(body, mediaContent);
File file = insert.execute();

-> 为什么 insert.execute() 不能捕获异常...?什么都不做。 -> 当我离开“fileItemData”时,我在谷歌驱动器中得到一个项目。那么它有什么问题呢?我正在尝试上传到 Google AppEngine 并存储到 AppEngine 上的 Google Drive。

【问题讨论】:

  • 我对出了什么问题感到困惑——你在insert.execute() 上遇到异常了吗?当你“离开”fileItemData时得到一个物品是什么意思?
  • 如果我在没有 fileItemData 的情况下插入 - 抱歉我应该说 mediaContent - >insert = driveService.files().insert(body);
  • 我没有遇到异常......插入媒体内容时没有任何反应。

标签: java google-app-engine google-drive-api


【解决方案1】:

你能用更小的数据试试你的代码吗,例如:

ByteArrayContent mediaContent = ByteArrayContent.fromString("text/plain", "Hello World")
driveService.files().insert(body, mediaContent).execute();

如果可行,请告诉我...

【讨论】:

  • 没用。仅当 i .insert(body).execute() (执行日志的下一行)而不是 .insert(body,mediaContent).execute() > (未执行日志的下一行并且在 appeEngine 上没有错误日志)时,插入 ... 后跟日志的行才有效。使用.insert(body).execute() 创建一个没有内容的完美谷歌驱动器条目。 Google Drive 只是按预期显示:>“抱歉,我们无法在原始来源中找到该文档。> 验证该文档是否仍然存在。” .
  • 我的猜测是发生了未捕获的异常。您是否尝试过使用 try {...} cache (Exception e) {//write e.getMessage() to log} 来包围调用?
  • 它被包围: } catch (GoogleJsonResponseException e) { } catch (HttpResponseException e) { } catch (IOException e) { } catch (Exception e) {
  • 我删除了这些触发器 /* * } catch (GoogleJsonResponseException e) { * } catch (HttpResponseException e) { * } catch (IOException e) { */ and only left "} catch (Exception e) {" 现在“Hello World”已存储到 Google 云端硬盘中。
  • 同样适用于我的 "byte[] fileItemData = blobstoreService.fetchData(blobKey, 0, 999999);" ...最后一次尝试是读取所有捕获(...我删除了..->只是为了重现问题
猜你喜欢
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 2014-07-23
  • 2021-01-30
  • 2022-01-27
  • 2016-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多