2014-11-15 107 views
2

我要加载一些数据到谷歌驱动器,但我不能使用recommended by Drive SDK way to do it有没有办法通过Drive SDK中的InputStream将文件上传到Google Drive?

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; 
} 

,因为我的数据并不总是具有java.io.File中作为源。有时它可能是来自加密存储或其他云存储的InputStream,因此我无法从中获取FileContent。有没有办法将InputStream中的数据加载到Google Drive,而无需在文件系统中存储数据(例如Dropbox API method "putFileOverwrite")?

回答

2

检查了这一点

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