使用Java API将文件上传到Google驱动器

问题描述

据我所知(距离我查看已经有几个月了 ,谷歌驱动器API 不支持(至今?)解决方法是考虑安装本机google驱动器共享,然后将要上传文件写入本地映射的共享文件夹中。然后它的谷歌驱动器问题来处理上传

解决方法

DocsService client = new DocsService("service name");
client.setUserCredentials(username,password);
File file = new File(filename);
URL url = new URL("https://docs.google.com/feeds/default/private/full/?ocr=true&convert=true");
String mimeType =     DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
DocumentEntry newDocument = new DocumentEntry();
newDocument.setTitle(new PlainTextConstruct(file.getName()));
newDocument.setMediaSource(new MediaFileSource(file,mimeType));
//newDocument.setFile(file,mimeType);
newDocument = client.insert(url,newDocument);
System.out.println("uploaded "+file.getName());
JOptionPane.showMessageDialog(null,"uploaded "+file.getName(),"alert",JOptionPane.ERROR_MESSAGE);

使用此代码,我上传文件,但该文件作为文档上传。表示我上传该文件的任何类型都将作为文档上传到Google驱动器