SDK 提供ObjectProfile方法获取文件基本信息。
ObjectProfile方法请求的 US3 API 为 HEADFile,具体详见HEADFileAPI文档。
文件基本信息说明
返回的文件基本信息包括:
| Name | Type | Description |
|---|---|---|
| Content-Type | String | 文件类型 |
| Content-Length | Integer | 文件长度 |
| X-Ufile-Create-Time | String | 文件上传时间 |
| X-Ufile-Storage-Class | String | 文件存储类型 |
| ETag | String | 文件的哈希值 |
| Last-Modified | String | 文件最后修改时间 |
| X-SessionId | String | 请求失败时返回本次请求的会话Id |
代码示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static void main(String[] args) {
// 配置参数
String keyName = "your-file-name.txt";
String bucketName = "your-bucket-name";
ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
try {
// 获取文件头信息
ObjectProfile profile = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.objectProfile(keyName, bucketName)
.execute();
System.out.println("Content-Type: " + profile.getContentType());
System.out.println("Content-Length: " + profile.getContentLength());
System.out.println("X-Ufile-Create-Time: " + profile.getCreateTime());
System.out.println("X-Ufile-Storage-Class: " + profile.getStorageType());
System.out.println("ETag: " + profile.geteTag());
System.out.println("Last-Modified: " + profile.getLastModified());
} catch (Exception e) {
System.err.println("获取文件信息失败: " + e.getMessage());
e.printStackTrace();
}
}
错误码
| HTTP 状态码 | RetCode | ErrMsg | 描述 |
|---|---|---|---|
| 400 | -148653 | bucket not exists | 存储空间不存在 |
| 400 | -15036 | check md5 failed | MD5校验失败 |
| 401 | -148643 | no authorization found | 上传凭证错误 |
| 403 | -148643 | invalid signature | API公私钥错误或者KeyName包含%、#、? |
| 404 | -148654 | file not exist | 源文件不存在 |