module Baidu::Pcs
Public Instance Methods
create_directory(dir_path)
click to toggle source
创建目录 为当前用户创建一个目录。 注意:这个是您使用的路径不正确,这个路径需要是您开启PCS权限的时候,填写的文件夹名称,而不能随便填写
# File lib/baidu/api/pcs.rb, line 38 def create_directory(dir_path) default = {method: "mkdir"} create_dir_url = pcs_base_url("file", default) response = RestClient.post(create_dir_url, path: dir_path) JSON.parse(response) end
delete(path)
click to toggle source
删除单个文件/目录。
# File lib/baidu/api/pcs.rb, line 62 def delete(path) default = {method: "delete"} create_dir_url = pcs_base_url("file", default) response = RestClient.post(create_dir_url, path: path) JSON.parse(response) end
download_single_file(file_path)
click to toggle source
注意: 此API不直接下载文件,而是直接返回下载链接
# File lib/baidu/api/pcs.rb, line 30 def download_single_file(file_path) default = {method: "download", path: file_path} "https://d.pcs.baidu.com/rest/2.0/pcs/file?#{query_params(default)}" end
get_image_thumbnail(image_path, height, width ,quality="100")
click to toggle source
获取指定图片文件的缩略图。
# File lib/baidu/api/pcs.rb, line 70 def get_image_thumbnail(image_path, height, width ,quality="100") default = {method: "generate", path: image_path, width: width, height: height, quality: quality} pcs_base_url("thumbnail", default) end
get_meta(path)
click to toggle source
获取单个文件/目录的元信息
# File lib/baidu/api/pcs.rb, line 46 def get_meta(path) default = {method: "meta", path: path} meta_url = pcs_base_url("file", default) get_response_json(meta_url) end
pcs_quota()
click to toggle source
获取当前用户空间配额信息。 pcs.baidu.com/rest/2.0/pcs/quota scope: netdisk
# File lib/baidu/api/pcs.rb, line 11 def pcs_quota quota_url = "#{pcs_base_url('quota', method: 'info')}" get_response_json(quota_url) end
upload_single_file(yun_path, source_file_path="", opts={})
click to toggle source
上传单个文件。 百度PCS服务目前支持最大2G的单个文件上传。 如需支持超大文件(>2G)的断点续传,请参考下面的“分片文件上传”方法。
# File lib/baidu/api/pcs.rb, line 19 def upload_single_file(yun_path, source_file_path="", opts={}) source_file = File.open(source_file_path) response = RestClient.post(upload_file_url(path: yun_path), file: source_file) JSON.parse(response) end
Private Instance Methods
pcs_base_url(path, params={})
click to toggle source
# File lib/baidu/api/pcs.rb, line 77 def pcs_base_url(path, params={}) "https://pcs.baidu.com/rest/2.0/pcs/#{path}?#{query_params(params)}" end
upload_file_url(params={})
click to toggle source
overwrite:表示覆盖同名文件; newcopy:表示生成文件副本并进行重命名,命名规则为“文件名_日期.后缀”。
# File lib/baidu/api/pcs.rb, line 83 def upload_file_url(params={}) default = {method: "upload", ondup: "newcopy"} params = params.merge(default) "https://c.pcs.baidu.com/rest/2.0/pcs/file?#{query_params(params)}" end