gpt4 book ai didi

java - 通过输入流将字节流上传到 Google Drive

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:21:55 24 4
gpt4 key购买 nike

我有字节流中的媒体内容,我正在尝试将该流上传到 Google 云端硬盘。

代码:

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();

异常:它只是说 null,但我不知道 null 是什么。

最佳答案

你可以尝试这样的事情:

file = service.files().insert(body, new InputStreamContent(mimeType, 
new ByteArrayInputStream(filename))).execute();

关于java - 通过输入流将字节流上传到 Google Drive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16558038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com