Java 通过输入流将字节流上载到Google驱动器
我有字节流中的媒体内容,我正试图将该流上传到Google Drive中 代码:Java 通过输入流将字节流上载到Google驱动器,java,google-drive-api,Java,Google Drive Api,我有字节流中的媒体内容,我正试图将该流上传到Google Drive中 代码: private static String writeToGoogleDrive(Drive service, String title, String description, String parentId, String mimeType, final byte[] filename) throws IOException { String URL=""; Fil
private static String writeToGoogleDrive(Drive service, String title,
String description, String parentId, String mimeType,
final byte[] filename) throws IOException {
String URL="";
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
if (parentId != null && parentId.length() > 0) {
body.setParents(Arrays.asList(new ParentReference().setId(parentId)));
}
try {
File file= service.files().insert(body, new AbstractInputStreamContent("") {
@Override
public boolean retrySupported() {
// TODO Auto-generated method stub
return false;
}
@Override
public long getLength() throws IOException {
// TODO Auto-generated method stub
System.out.println("the value of the length of the file is "+filename.length);
return filename.length;
}
@Override
public InputStream getInputStream() throws IOException {
// TODO Auto-generated method stub
return new ByteArrayInputStream(filename);
}
}).execute();
例外:它只是说空,但我不知道空是什么。你可以试试这样的方法:
file = service.files().insert(body, new InputStreamContent(mimeType,
new ByteArrayInputStream(filename))).execute();
这里定义了服务的位置?