我试图通过编程获得我的google drive中的文件夹名称,并在文件夹内创建一个文件夹,但没有办法。
我已经审查了这个文档。
但我如何得到一个特定的文件夹,并创建另一个吗?
好吧,我需要更新位图到谷歌驱动器。我试图用这个代码,但不工作
String IdFolder = (String) objects[0];
Bitmap bitmapUpload = (Bitmap) objects[1];
File fileMetadata = new File();
fileMetadata.setTitle("photo.jpg");
fileMetadata.setParents(Collections.singletonList(new ParentReference().setId(IdFolder)));
File file = mService.files().insert(fileMetadata, bitmapUpload)
.setFields("id, parents")
.execute();
System.out.println("File ID: " + file.getId());
我已经试过了。
String IdFolder = (String) objects[0];
Bitmap bitmapUpload = (Bitmap) objects[1];
int byteSize = bitmapUpload.getRowBytes() * bitmapUpload.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(byteSize);
bitmap.copyPixelsToBuffer(byteBuffer);
byte[] byteArray = byteBuffer.array();
ByteArrayInputStream bs = new ByteArrayInputStream(byteArray);
File fileMetadata = new File();
fileMetadata.setTitle("photo.jpg");
fileMetadata.setParents(Collections.singletonList(new ParentReference().setId(IdFolder)));
File file = mService.files().insert(fileMetadata, bs)
.setFields("id, parents")
.execute();
System.out.println("File ID: " + file.getId());
但不工作。只是说。
com.google.api.client.http.abstract inputstreamcontent(输入流内容)
?¿?
我试着做了一个python函数,你可以用你想要的方式使用它。
def create_folder_in_folder(folder_name,parent_folder_id):
file_metadata = {
'name' : folder_name,
'parents' : [folder_id],
'mimeType' : 'application/vnd.google-apps.folder'
}
file = drive_service.files().create(body=file_metadata,
fields='id').execute()
print ('Folder ID: %s' % file.get('id'))
希望能帮到你。