如何在pc端批量自动上传文件到百度云盘(其他云盘)

来源:互联网 发布:程序员鼓励师 编辑:程序博客网 时间:2024/05/16 05:32

Hi,大家好,最近一直有一些关于工作上的烦恼,进而有一些想法。下面是一个例子,或者说是一个故事吧,每个想法都是从一个故事开始的,是吧。

我们公司是的工作笔记本一般是三年就可以申请换新机,而我目前正在使用的笔记本。由于之前有许多内容,一时之间,切换电脑,使用新的电脑还不习惯,而且关键是,旧电脑上有好多资料,所以就打算把之前的内容都在网上做个备份。

很高兴百度云盘能坚持到现在还能为广大码人服务,但是我不是API,所以有很多限制,比如,上传文件大小不能超过4G,同时上传文件不能超过500个等。所以想用java语言实现,把本地某个目录下的文件都自动打包上传到云盘上,不知有百度云盘API可用没。呵呵

目前可以用压缩软件来这么做:

点击鼠标右键,选择“添加到压缩文件”

选择“文件”,把下列选项打钩

选中“把每个文件夹放到单独的压缩包中”




1.首先加入百度开发者:http://developer.baidu.com/dev#/create 
 2.任意创建一个应用获取API Key并开通PCS API权限,开放API > API管理 > API列表 > API服务 > PCS API > 开启 
3.通过刚刚新建应用的API Key获取device code和user_code 

curl -k -L -d "client_id=<api_id>&response_type=device_code&scope=basic,netdisk" \ 
"https://openapi.baidu.com/oauth/2.0/device/code" 


4.在浏览器打开https://openapi.baidu.com/device输入获取到的user_code并连接,然后通过device code获取refresh_token和access_token:


curl -k -L -d "grant_type=device_token&code=<code>&client_id=<api_id>&client_secret=<api_secret>" \ 
"https://openapi.baidu.com/oauth/2.0/token" 


5.此时通过access_token就可对网盘文件进行操作了,获取到access_token的有效期为30天,过期后通过refresh_token重新获取access_token

curl -k -L -d "grant_type=refresh_token&refresh_token=<refresh_token>&client_id=\ 
<api_id>&client_secret=<api_secret>" 

6.获取网盘配额: 

curl -k -L "https://pcs.baidu.com/rest/2.0/pcs/quota?method=\ 
info&access_token=<access_token>" 

7.上传文件: 

curl -k -L -F "file=@haiyun.me.tar.gz" "https://c.pcs.baidu.com/rest/2.0/pcs/file?method=upload&\ 
access_token=<access_token>&path=/apps/pcsupload/haiyun.me.tar.gz" 

8.下载文件: 

curl -k -O "https://d.pcs.baidu.com/rest/2.0/pcs/file?method=download&access_token=<access_token>&\ 
path=/apps/pcsupload/haiyun.me.tar.gz" 


9.删除文件: 

curl -k -L "https://pcs.baidu.com/rest/2.0/pcs/file?method=delete&access_token=<access_token>\ 
&path=/apps/pcsupload/haiyun.me.tar.gz" 


10.复制文件: 

curl -k -L "https://c.pcs.baidu.com/rest/2.0/pcs/file?method=copy&access_token=<access_token>\ 
&from=/apps/pcsupload/haiyun.me.tar.gz&to=/apps/pcsupload/www.haiyun.me.tar.gz" 


11.列出目录内文件: 

curl -k -L "https://pcs.baidu.com/rest/2.0/pcs/file?method=list&access_token=<access_token>\ 
&path=/apps/pcsupload/" 


更多操作:http://developer.baidu.com/wiki/index.php?title=docs/pcs/rest/file_data_apis_list 

以上摘自http://www.haiyun.me/archives/859.html 
0 0
原创粉丝点击