简体   繁体   English

是否可以通过Drive SDK中的InputStream将文件上传到Google Drive?

[英]Is there a way to upload file to Google Drive from InputStream in Drive SDK?

I have to load some data to Google Drive, but I can't use recommended by Drive SDK way to do it : 我必须将一些数据加载到Google云端硬盘,但是我无法使用Drive SDK推荐的方式来做到这一点

FileContent fileContent = new FileContent(mimeType, dataFile);
try {
  File file = service.files().insert(body, fileContent).execute();
  return file;
} catch (IOException e) {
  System.out.println("An error occured: " + e);
  return null;
}

because my data isn't always has the java.io.File as a source. 因为我的数据并不总是以java.io.File作为源。 Sometimes it may be an InputStream from encrypted storage or from other cloud storage and therefore I can't get FileContent from it. 有时它可能是来自加密存储或其他云存储的InputStream,因此我无法从中获取FileContent。 Is there a way to load data from InputStream to Google Drive without their intermediate storing on file system (as for Dropbox API method "putFileOverwrite" , for example)? 有没有一种方法可以将InputStream的数据加载到Google Drive,而无需将其中间存储在文件系统上(例如,对于Dropbox API方法“ putFileOverwrite” )?

Check this out 看一下这个

 File file= drive.files().insert(body,
                                new InputStreamContent(
                                        fileItemStream
                                                .getContentType(),
                                        new ByteArrayInputStream(
                                                IOUtils.toByteArray(fileInputStream)))).execute;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM