public class QiNiuUpload extends Object
七牛云上传
2019-11-23 11:23
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
accessKey
七牛云accessKey信息,可以在{https://portal.qiniu.com/user/key}查看
|
static com.qiniu.storage.Region |
beiMei
Region对应机房:北美
|
static String |
bucket
七牛云存储桶名称
|
static com.qiniu.storage.Region |
huaBei
Region对应机房:华北
|
static com.qiniu.storage.Region |
huaDong
Region对应机房:华东
|
static com.qiniu.storage.Region |
huaNan
Region对应机房:华南
|
static com.qiniu.storage.Region |
region
设置默认region
|
static String |
secretKey
七牛云secretKey信息,可以在{https://portal.qiniu.com/user/key}查看
|
static com.qiniu.storage.Region |
xinJiaPo
Region对应机房:新加坡
|
| 构造器和说明 |
|---|
QiNiuUpload() |
| 限定符和类型 | 方法和说明 |
|---|---|
com.qiniu.http.Response |
asyncFetch(String url,
String bucket,
String key)
异步第三方资源抓取 从指定 URL 抓取资源,并将该资源存储到指定空间中。
|
static com.qiniu.http.Response |
copy(String fromFileKey,
String toFileKey)
复制文件,要求空间在同一账号下
使用默认upToken、默认的region为华东
|
static com.qiniu.http.Response |
copy(String fromBucket,
String fromFileKey,
String toBucket,
String toFileKey,
boolean force)
复制文件,要求空间在同一账号下,可以设置force参数为true强行覆盖空间已有同名文件
|
static com.qiniu.http.Response |
delete(String key)
删除空间中的文件
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.BatchStatus[] |
delete(String[] keyList)
批量删除空间中的文件
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.BatchStatus[] |
delete(String[] keyList,
com.qiniu.storage.Region region)
批量删除空间中的文件
|
static com.qiniu.http.Response |
delete(String key,
com.qiniu.storage.Region region)
删除空间中的文件
|
static String |
downloadString(String url,
String customCharsetName)
下载远程文本
|
static com.qiniu.storage.model.FetchRet |
fetch(String remoteSrcUrl,
String key)
抓取网络资源到空间
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.FetchRet |
fetch(String remoteSrcUrl,
String key,
com.qiniu.storage.Region region)
抓取网络资源到空间
|
static com.qiniu.storage.BucketManager |
getBucketManager(com.qiniu.storage.Region region)
获取七牛云桶管理器
参考文档:资源管理
|
static String |
getEtag(byte[] data)
计算二进制数据的etag
|
static String |
getEtag(byte[] data,
int offset,
int length)
计算二进制数据的etag
etag算法是七牛用来标志数据唯一性的算法。
|
static String |
getEtag(File file)
计算文件内容的etag
|
static String |
getEtag(InputStream in,
long len)
计算输入流的etag,如果计算完毕不需要这个InputStream对象,请自行关闭流
etag算法是七牛用来标志数据唯一性的算法。
|
static String |
getEtag(String filePath)
计算文件内容的etag
|
static com.qiniu.storage.model.FileInfo |
getFileInfo(String key)
获取七牛云文件信息
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.FileInfo |
getFileInfo(String key,
com.qiniu.storage.Region region)
获取七牛云文件信息
|
static com.qiniu.storage.BucketManager.FileListIterator |
getFilesList(String prefix,
int limit,
String delimiter)
获取空间文件列表
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.BucketManager.FileListIterator |
getFilesList(String prefix,
int limit,
String delimiter,
com.qiniu.storage.Region region)
获取空间文件列表
|
static String |
getPrivateDownloadUrl(String publicUrl,
long expireInSeconds)
获取私有空间文件链接进行私有授权签名
|
static String |
getUploadToken()
一般情况下可通过此方法获取token
有效时长3600秒
|
static String |
getUploadToken(long expires)
生成token
指定有效时长
|
static String |
getUploadToken(String key)
同名文件覆盖操作、只能上传指定key的文件可以可通过此方法获取token
这个文件名称同时是客户端上传代码中指定的文件名,两者必须一致
|
static String |
getUploadToken(String key,
long expires)
生成token
指定key、指定有效时长
同名文件覆盖操作、只能上传指定key的文件
|
String |
getUploadToken(String key,
long expires,
com.qiniu.util.StringMap policy,
boolean strict)
生成上传token
|
static String |
getUploadToken(com.qiniu.util.StringMap policy)
一般情况下可通过此方法获取token
自定义上传策略
有效时长默认3600s
|
static String |
getUploadToken(String key,
com.qiniu.util.StringMap policy)
同名文件覆盖操作、只能上传指定key的文件可以可通过此方法获取token
这个文件名称同时是客户端上传代码中指定的文件名,两者必须一致
自定义上传策略
有效时长默认3600s
|
static com.qiniu.http.Response |
move(String fromFileKey,
String toFileKey)
移动文件。
|
static com.qiniu.http.Response |
move(String fromBucket,
String fromFileKey,
String toBucket,
String toFileKey,
boolean force)
移动文件,要求空间在同一账号下, 可以添加force参数为true强行移动文件。
|
static com.qiniu.http.Response |
rename(String oldFileKey,
String newFileKey)
重命名空间中的文件
使用默认upToken、默认的region为华东
|
static com.qiniu.http.Response |
rename(String bucket,
String oldFileKey,
String newFileKey,
boolean force)
重命名空间中的文件
|
static com.qiniu.http.Response |
setFileType(String key,
com.qiniu.storage.Region region,
String newMimeType)
修改文件类型
|
static com.qiniu.http.Response |
setFileType(String key,
String newMimeType)
修改文件类型
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
stringUploader(String key,
String str)
字符串数据上传
使用默认字符集编码(UTF-8)
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
stringUploader(String key,
String upToken,
com.qiniu.storage.Region region,
String str,
String charsetName)
字符串数据上传
|
static com.qiniu.storage.model.DefaultPutRet |
stringUploader(String key,
String str,
String charsetName)
字符串数据上传
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(byte[] uploadBytes,
String key)
七牛云字节数组文件上传
可以支持将内存中的字节数组上传到空间中。
|
static void |
uploader(byte[] data,
String key,
com.qiniu.util.StringMap params,
String mime,
boolean checkCrc,
com.qiniu.storage.UpCompletionHandler handler)
七牛云异步上传数据
将内存中的字节数组异步上传到空间中
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(byte[] uploadBytes,
String key,
String upToken,
com.qiniu.storage.Region region)
七牛云字节数组文件上传
可以支持将内存中的字节数组上传到空间中。
|
static void |
uploader(byte[] data,
String key,
String token,
com.qiniu.util.StringMap params,
String mime,
boolean checkCrc,
com.qiniu.storage.UpCompletionHandler handler,
com.qiniu.storage.Region region)
七牛云异步上传数据
将内存中的字节数组异步上传到空间中
|
static void |
uploader(byte[] data,
String key,
String token,
com.qiniu.storage.UpCompletionHandler handler,
com.qiniu.storage.Region region)
七牛云异步上传数据精简版
将内存中的字节数组异步上传到空间中
取消一些不常用的参数
|
static void |
uploader(byte[] data,
String key,
com.qiniu.storage.UpCompletionHandler handler)
七牛云异步上传数据精简版
将内存中的字节数组异步上传到空间中
取消一些不常用的参数
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(File cosFile,
String key)
服务端本地文件直接上传到七牛云
大文件采用分片上传的形式
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(File cosFile,
String key,
File recorder)
服务端本地文件直接上传到七牛云
大文件采用分片上传的形式
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(File cosFile,
String key,
String upToken,
com.qiniu.storage.Region region,
File recorderFile)
服务端本地文件直接上传到七牛云
大文件采用分片上传的形式
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(InputStream cosFile,
String key)
七牛云数据流文件上传
适用于所有的InputStream子类
使用默认upToken、默认的region为华东
|
static com.qiniu.storage.model.DefaultPutRet |
uploader(InputStream cosFile,
String key,
String upToken,
com.qiniu.storage.Region region)
七牛云数据流文件上传
适用于所有的InputStream子类
|
public static com.qiniu.storage.Region huaDong
public static com.qiniu.storage.Region huaBei
public static com.qiniu.storage.Region huaNan
public static com.qiniu.storage.Region beiMei
public static com.qiniu.storage.Region xinJiaPo
public static String accessKey
public static String secretKey
public static String bucket
public static com.qiniu.storage.Region region
public static com.qiniu.storage.BucketManager getBucketManager(com.qiniu.storage.Region region)
region - 需要上传到的区域BucketManager类public static com.qiniu.storage.model.DefaultPutRet uploader(File cosFile, String key, String upToken, com.qiniu.storage.Region region, File recorderFile) throws IOException
cosFile - 需要上传的文件对象key - 上传文件保存的文件名upToken - 上传凭证region - 需要上传到的区域recorderFile - 断点记录对象[只有断点上传有效,用来记录当前上传进度的]IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet uploader(File cosFile, String key) throws IOException
cosFile - 需要上传的文件对象key - 上传文件保存的文件名IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet uploader(File cosFile, String key, File recorder) throws IOException
cosFile - 需要上传的文件对象key - 上传文件保存的文件名recorder - 断点记录对象[只有断点上传有效,用来记录当前上传进度的]IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet uploader(InputStream cosFile, String key, String upToken, com.qiniu.storage.Region region) throws IOException
cosFile - 需要上传的数据流key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名upToken - 七牛云上传的tokenregion - 需要上传到的区域IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet uploader(InputStream cosFile, String key) throws IOException
cosFile - 需要上传的数据流key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet stringUploader(String key, String upToken, com.qiniu.storage.Region region, String str, String charsetName) throws IOException
key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名upToken - 七牛云上传的tokenregion - 需要上传到的区域str - 需要上传的字符串charsetName - 字符集(如:UTF-8)IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet stringUploader(String key, String str, String charsetName) throws IOException
key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名str - 需要上传的字符串charsetName - 字符集(如:UTF-8)IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet stringUploader(String key, String str) throws IOException
key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名str - 需要上传的字符串IOExceptionpublic static String downloadString(String url, String customCharsetName)
url - 请求的urlcustomCharsetName - 自定义的字符集public static com.qiniu.storage.model.DefaultPutRet uploader(byte[] uploadBytes,
String key,
String upToken,
com.qiniu.storage.Region region)
throws IOException
uploadBytes - 需要上传的字节数组文件key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名upToken - 七牛云上传的tokenregion - 需要上传到的区域IOExceptionpublic static com.qiniu.storage.model.DefaultPutRet uploader(byte[] uploadBytes,
String key)
throws IOException
uploadBytes - 需要上传的字节数组文件key - 上传的路径,默认不指定key的情况下,以文件内容的hash值作为文件名IOExceptionpublic static void uploader(byte[] data,
String key,
String token,
com.qiniu.util.StringMap params,
String mime,
boolean checkCrc,
com.qiniu.storage.UpCompletionHandler handler,
com.qiniu.storage.Region region)
throws IOException
data - 上传的数据key - 上传数据保存的文件名token - 上传凭证params - 自定义参数,如 params.put("x:foo", "foo")mime - 指定文件mimeTypecheckCrc - 是否验证crc32handler - 上传完成的回调函数region - 需要上传到的区域IOExceptionpublic static void uploader(byte[] data,
String key,
com.qiniu.util.StringMap params,
String mime,
boolean checkCrc,
com.qiniu.storage.UpCompletionHandler handler)
throws IOException
data - 上传的数据key - 上传数据保存的文件名params - 自定义参数,如 params.put("x:foo", "foo")mime - 指定文件mimeTypecheckCrc - 是否验证crc32handler - 上传完成的回调函数IOExceptionpublic static void uploader(byte[] data,
String key,
String token,
com.qiniu.storage.UpCompletionHandler handler,
com.qiniu.storage.Region region)
throws IOException
data - 上传的数据key - 上传数据保存的文件名token - 上传凭证handler - 上传完成的回调函数region - 需要上传到的区域IOExceptionpublic static void uploader(byte[] data,
String key,
com.qiniu.storage.UpCompletionHandler handler)
throws IOException
data - 上传的数据key - 上传数据保存的文件名handler - 上传完成的回调函数IOExceptionpublic static com.qiniu.storage.model.FileInfo getFileInfo(String key, com.qiniu.storage.Region region) throws com.qiniu.common.QiniuException
key - key值region - 需要上传到的区域com.qiniu.common.QiniuExceptionpublic static com.qiniu.storage.model.FileInfo getFileInfo(String key) throws com.qiniu.common.QiniuException
key - key值com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response setFileType(String key, com.qiniu.storage.Region region, String newMimeType) throws com.qiniu.common.QiniuException
key - key值region - 区域信息newMimeType - 需要修改的新的文件类型com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response setFileType(String key, String newMimeType) throws com.qiniu.common.QiniuException
key - key值newMimeType - 需要修改的新的文件类型com.qiniu.common.QiniuExceptionpublic static String getPrivateDownloadUrl(String publicUrl, long expireInSeconds)
publicUrl - 待签名文件url,如 http://img.domain.com/u/3.jpg 、
http://img.domain.com/u/3.jpg?imageView2/1/w/120expireInSeconds - 有效时长,单位秒。默认3600spublic static com.qiniu.storage.BucketManager.FileListIterator getFilesList(String prefix, int limit, String delimiter, com.qiniu.storage.Region region)
prefix - 文件名前缀limit - 每次迭代的长度限制,最大1000,推荐值 1000delimiter - 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串region - 区域信息public static com.qiniu.storage.BucketManager.FileListIterator getFilesList(String prefix, int limit, String delimiter)
prefix - 文件名前缀limit - 每次迭代的长度限制,最大1000,推荐值 1000delimiter - 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串public static com.qiniu.storage.model.FetchRet fetch(String remoteSrcUrl, String key, com.qiniu.storage.Region region) throws com.qiniu.common.QiniuException
remoteSrcUrl - 远程url、需要抓取的远程urlkey - 你的文件的key值region - 区域信息com.qiniu.common.QiniuExceptionpublic static com.qiniu.storage.model.FetchRet fetch(String remoteSrcUrl, String key) throws com.qiniu.common.QiniuException
remoteSrcUrl - 远程url、需要抓取的远程urlkey - 你的文件的key值com.qiniu.common.QiniuExceptionpublic com.qiniu.http.Response asyncFetch(String url, String bucket, String key) throws com.qiniu.common.QiniuException
url - 待抓取的文件链接,支持设置多个,以';'分隔bucket - 文件抓取后保存的空间key - 文件抓取后保存的文件名com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response delete(String key, com.qiniu.storage.Region region) throws com.qiniu.common.QiniuException
key - 你的文件的key值region - 区域信息com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response delete(String key) throws com.qiniu.common.QiniuException
key - 你的文件的key值com.qiniu.common.QiniuExceptionpublic static com.qiniu.storage.model.BatchStatus[] delete(String[] keyList, com.qiniu.storage.Region region) throws com.qiniu.common.QiniuException
keyList - 文件key,单次批量请求的文件数量不得超过1000region - 区域信息com.qiniu.common.QiniuExceptionpublic static com.qiniu.storage.model.BatchStatus[] delete(String[] keyList) throws com.qiniu.common.QiniuException
keyList - 文件key,单次批量请求的文件数量不得超过1000com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response rename(String bucket, String oldFileKey, String newFileKey, boolean force) throws com.qiniu.common.QiniuException
bucket - 空间名称oldFileKey - 旧的文件名称newFileKey - 新的文件名称force - 强制覆盖空间中已有同名(和 newFileKey 相同)的文件com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response rename(String oldFileKey, String newFileKey) throws com.qiniu.common.QiniuException
oldFileKey - 旧的文件名称newFileKey - 新的文件名称com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response copy(String fromBucket, String fromFileKey, String toBucket, String toFileKey, boolean force) throws com.qiniu.common.QiniuException
fromBucket - 源空间名称fromFileKey - 源文件名称toBucket - 目的空间名称toFileKey - 目的文件名称force - 强制覆盖空间中已有同名(和 toFileKey 相同)的文件com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response copy(String fromFileKey, String toFileKey) throws com.qiniu.common.QiniuException
fromFileKey - 源文件名称toFileKey - 目的文件名称com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response move(String fromBucket, String fromFileKey, String toBucket, String toFileKey, boolean force) throws com.qiniu.common.QiniuException
fromBucket - 源空间名称fromFileKey - 源文件名称toBucket - 目的空间名称toFileKey - 目的文件名称force - 强制覆盖空间中已有同名(和 toFileKey 相同)的文件com.qiniu.common.QiniuExceptionpublic static com.qiniu.http.Response move(String fromFileKey, String toFileKey) throws com.qiniu.common.QiniuException
fromFileKey - 源文件名称toFileKey - 目的文件名称com.qiniu.common.QiniuExceptionpublic static String getUploadToken()
public static String getUploadToken(com.qiniu.util.StringMap policy)
自定义上传策略 有效时长默认3600s
policy - 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
scope通过 bucket、key间接设置,deadline 通过 expires 间接设置public static String getUploadToken(String key)
key - 七牛云上传路径,可为 nullpublic static String getUploadToken(String key, com.qiniu.util.StringMap policy)
自定义上传策略 有效时长默认3600s
key - 七牛云上传路径,可为 nullpolicy - 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
scope通过 bucket、key间接设置,deadline 通过 expires 间接设置public static String getUploadToken(long expires)
expires - 有效时长,单位秒。默认3600spublic static String getUploadToken(String key, long expires)
key - 七牛云上传唯一标识 ,同名的覆盖,可为nullexpires - 有效时长,单位秒。默认3600spublic String getUploadToken(String key, long expires, com.qiniu.util.StringMap policy, boolean strict)
key - key,可为 nullexpires - 有效时长,单位秒。默认3600spolicy - 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
scope通过 bucket、key间接设置,deadline 通过 expires 间接设置strict - 是否去除非限定的策略字段,默认truepublic static String getEtag(InputStream in, long len) throws IOException
in - 数据输入流len - 数据流长度IOExceptionpublic static String getEtag(byte[] data, int offset, int length)
data - 二进制数据offset - 起始字节索引length - 需要计算的字节长度public static String getEtag(byte[] data)
data - 二进制数据public static String getEtag(File file) throws IOException
file - 文件对象IOExceptionpublic static String getEtag(String filePath) throws IOException
filePath - 文件路径IOExceptionCopyright © 2021. All rights reserved.