[英]Is there a way to upload file to Google Drive from InputStream in Drive SDK?
我必須將一些數據加載到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;
}
因為我的數據並不總是以java.io.File作為源。 有時它可能是來自加密存儲或其他雲存儲的InputStream,因此我無法從中獲取FileContent。 有沒有一種方法可以將InputStream的數據加載到Google Drive,而無需將其中間存儲在文件系統上(例如,對於Dropbox API方法“ putFileOverwrite” )?
看一下這個
File file= drive.files().insert(body,
new InputStreamContent(
fileItemStream
.getContentType(),
new ByteArrayInputStream(
IOUtils.toByteArray(fileInputStream)))).execute;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.