使用java api上传文件到谷歌驱动器 [英] upload file into google drive using java api

查看:137
本文介绍了使用java api上传文件到谷歌驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 drive

using this code i upload file but that file is upload as a document. means i upload any type of that file is upload as a document in to google drive

推荐答案

据我知道了(自从我看了几个月后),这是 not(yet?)支持的谷歌驱动器API。
作为解决方法,请考虑安装本地谷歌驱动器共享并将要上载的文件写入本地映射的共享文件夹。然后,它的谷歌驱动器问题来处理上传。

As far as I know (its been a few month since I looked) this is not (yet?) supported by the google drive API. As a workaround consider installing the native google drive share and write the files you want to upload into the locally mapped shared folder. Then its google drives problem to handle the upload.

这篇关于使用java api上传文件到谷歌驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆