|
18 | 18 | public final class UploadManager { |
19 | 19 | private final Client client; |
20 | 20 | private final Recorder recorder; |
21 | | - private Configuration configuration; |
| 21 | + private Configuration configuration; |
22 | 22 |
|
23 | 23 | /** |
24 | 24 | * 构建一个非断点续传的上传对象 |
@@ -60,6 +60,31 @@ private static void checkArgs(final String key, byte[] data, File f, String toke |
60 | 60 | } |
61 | 61 | } |
62 | 62 |
|
| 63 | + /** |
| 64 | + * 过滤用户自定义参数,只有参数名以<code>x:</code>开头的参数才会被使用 |
| 65 | + * |
| 66 | + * @param params 待过滤的用户自定义参数 |
| 67 | + * @return 过滤后的用户自定义参数 |
| 68 | + */ |
| 69 | + private static StringMap filterParam(StringMap params) { |
| 70 | + final StringMap ret = new StringMap(); |
| 71 | + if (params == null) { |
| 72 | + return ret; |
| 73 | + } |
| 74 | + params.forEach(new StringMap.Consumer() { |
| 75 | + @Override |
| 76 | + public void accept(String key, Object value) { |
| 77 | + if (value == null) { |
| 78 | + return; |
| 79 | + } |
| 80 | + String val = value.toString(); |
| 81 | + if ((key.startsWith("x:") || key.startsWith("x-qn-meta-")) && !val.equals("")) { |
| 82 | + ret.put(key, val); |
| 83 | + } |
| 84 | + } |
| 85 | + }); |
| 86 | + return ret; |
| 87 | + } |
63 | 88 |
|
64 | 89 | /** |
65 | 90 | * 上传字节数组 |
@@ -90,6 +115,7 @@ public Response put(final byte[] data, final String key, final String token, Str |
90 | 115 | if (mime == null) { |
91 | 116 | mime = Client.DefaultMime; |
92 | 117 | } |
| 118 | + params = filterParam(params); |
93 | 119 | return new FormUploader(client, token, key, data, params, mime, checkCrc, configuration).upload(); |
94 | 120 | } |
95 | 121 |
|
@@ -145,6 +171,7 @@ public Response put(File file, String key, String token, StringMap params, |
145 | 171 | if (mime == null) { |
146 | 172 | mime = Client.DefaultMime; |
147 | 173 | } |
| 174 | + params = filterParam(params); |
148 | 175 | long size = file.length(); |
149 | 176 | if (size <= configuration.putThreshold) { |
150 | 177 | return new FormUploader(client, token, key, file, params, mime, checkCrc, configuration).upload(); |
@@ -172,6 +199,7 @@ public void asyncPut(final byte[] data, final String key, final String token, St |
172 | 199 | if (mime == null) { |
173 | 200 | mime = Client.DefaultMime; |
174 | 201 | } |
| 202 | + params = filterParam(params); |
175 | 203 | new FormUploader(client, token, key, data, params, mime, checkCrc, configuration).asyncUpload(handler); |
176 | 204 | } |
177 | 205 |
|
|
0 commit comments