From dbc3ba5281b389471209b0c298f4fdf4c83643f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=98=E6=BD=98?= Date: Wed, 13 Mar 2019 14:38:03 +0800 Subject: [PATCH 1/4] FormUpload With InputStream --- src/main/java/com/qiniu/common/Region.java | 2 +- .../java/com/qiniu/storage/UploadManager.java | 32 +++++++ src/main/java/com/qiniu/util/IOUtils.java | 22 +++++ src/test/java/test/com/qiniu/TestConfig.java | 5 + src/test/java/test/com/qiniu/rtc/RtcTest.java | 1 + .../com/qiniu/storage/FormUploadTest2.java | 73 +++++++++++++++ .../com/qiniu/streaming/StreamingTest.java | 93 +++++++++---------- 7 files changed, 179 insertions(+), 49 deletions(-) create mode 100644 src/main/java/com/qiniu/util/IOUtils.java create mode 100644 src/test/java/test/com/qiniu/storage/FormUploadTest2.java diff --git a/src/main/java/com/qiniu/common/Region.java b/src/main/java/com/qiniu/common/Region.java index 3c983eff8..d283f68b6 100644 --- a/src/main/java/com/qiniu/common/Region.java +++ b/src/main/java/com/qiniu/common/Region.java @@ -58,7 +58,7 @@ public String getApiHost() { /** * 域名构造器 */ - static class Builder { + public static class Builder { protected Region region; public Builder() { diff --git a/src/main/java/com/qiniu/storage/UploadManager.java b/src/main/java/com/qiniu/storage/UploadManager.java index 41a5b9041..6a12d48e4 100644 --- a/src/main/java/com/qiniu/storage/UploadManager.java +++ b/src/main/java/com/qiniu/storage/UploadManager.java @@ -3,6 +3,7 @@ import com.qiniu.common.QiniuException; import com.qiniu.http.Client; import com.qiniu.http.Response; +import com.qiniu.util.IOUtils; import com.qiniu.util.StringMap; import java.io.File; @@ -86,6 +87,37 @@ public void accept(String key, Object value) { }); return ret; } + + /** + * 上传字节流,表单形式 + * 合适小文件,大文件请用流式上传 + * @param inputStream + * @param key + * @param token + * @return + * @throws QiniuException + */ + public Response putWithForm(InputStream inputStream, String key, String token) throws QiniuException, IOException { + return putWithForm(inputStream, key, token, null, null, false); + } + + /** + * 上传字节流,表单形式 + * 合适小文件,大文件请用流式上传 + * @param inputStream + * @param key + * @param token + * @param params + * @param mime + * @param checkCrc + * @return + * @throws QiniuException + */ + public Response putWithForm(InputStream inputStream, String key, String token, StringMap params, + String mime, boolean checkCrc) throws QiniuException, IOException { + byte[] data = IOUtils.toByteArray(inputStream); + return put(data, key, token, params, mime, checkCrc); + } /** * 上传字节数组 diff --git a/src/main/java/com/qiniu/util/IOUtils.java b/src/main/java/com/qiniu/util/IOUtils.java new file mode 100644 index 000000000..0f71b5e23 --- /dev/null +++ b/src/main/java/com/qiniu/util/IOUtils.java @@ -0,0 +1,22 @@ +package com.qiniu.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ByteArrayOutputStream; + +public class IOUtils { + + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + public static byte[] toByteArray(final InputStream input) throws IOException { + try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int n; + while (-1 != (n = input.read(buffer))) { + output.write(buffer, 0, n); + } + return output.toByteArray(); + } + } + +} diff --git a/src/test/java/test/com/qiniu/TestConfig.java b/src/test/java/test/com/qiniu/TestConfig.java index f81f4c8eb..17561d119 100644 --- a/src/test/java/test/com/qiniu/TestConfig.java +++ b/src/test/java/test/com/qiniu/TestConfig.java @@ -2,6 +2,8 @@ import com.qiniu.util.Auth; +import test.com.qiniu.storage.FormUploadTest2; + public final class TestConfig { //dummy: ak, sk, ... @@ -44,7 +46,10 @@ public static boolean isTravis() { } public static void main(String[] args) { + FormUploadTest2 t = new FormUploadTest2(); try { + t.testFormUploadWithInputStream(); + t.testFormUploadWithInputStreamWithPolicy(); System.out.println("done"); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/java/test/com/qiniu/rtc/RtcTest.java b/src/test/java/test/com/qiniu/rtc/RtcTest.java index 256d62dd9..d30ad78e4 100644 --- a/src/test/java/test/com/qiniu/rtc/RtcTest.java +++ b/src/test/java/test/com/qiniu/rtc/RtcTest.java @@ -10,6 +10,7 @@ public class RtcTest { + private Auth auth = TestConfig.testAuth; private RtcAppManager manager = new RtcAppManager(auth); private RtcRoomManager rmanager = new RtcRoomManager(auth); diff --git a/src/test/java/test/com/qiniu/storage/FormUploadTest2.java b/src/test/java/test/com/qiniu/storage/FormUploadTest2.java new file mode 100644 index 000000000..17d750299 --- /dev/null +++ b/src/test/java/test/com/qiniu/storage/FormUploadTest2.java @@ -0,0 +1,73 @@ +package test.com.qiniu.storage; + +import java.io.FileInputStream; +import java.io.InputStream; + +import org.junit.Test; + +import com.qiniu.common.QiniuException; +import com.qiniu.http.Response; +import com.qiniu.storage.Configuration; +import com.qiniu.storage.UploadManager; +import com.qiniu.util.StringMap; + +import test.com.qiniu.TempFile; +import test.com.qiniu.TestConfig; + +import static org.junit.Assert.*; + +public class FormUploadTest2 { + + UploadManager uploadManager = new UploadManager(new Configuration()); + + /** + * 测试传入inputStream的表单上传 + * 检测reqid是否为Null + * 检测状态码是否为200 + */ + @Test + public void testFormUploadWithInputStream() { + + String token = TestConfig.testAuth.uploadToken(TestConfig.testBucket_z0, TestConfig.testBucket_z0, 3600, null); + System.out.println(token); + + try { + InputStream inputStream = new FileInputStream(TempFile.createFile(11)); + Response response = uploadManager.putWithForm(inputStream, TestConfig.testBucket_z0, token); + System.out.println(response.reqId); + System.out.println(response.statusCode); + System.out.println(response.bodyString()); + assertNotNull(response.reqId); + assertEquals(200, response.statusCode); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 测试传入inputStream的表单上传 + * 检测reqid是否为Null + * 检测状态码是否为614 + */ + @Test + public void testFormUploadWithInputStreamWithPolicy() { + + StringMap putPolicy = new StringMap(); + putPolicy.put("insertOnly", 1); + String token = TestConfig.testAuth.uploadToken(TestConfig.testBucket_z0, TestConfig.testBucket_z0, 3600, putPolicy); + System.out.println(token); + + try { + InputStream inputStream = new FileInputStream(TempFile.createFile(11)); + uploadManager.putWithForm(inputStream, TestConfig.testBucket_z0, token); + } catch (Exception e) { + if (e instanceof QiniuException) { + QiniuException ex = (QiniuException) e; + System.out.println(ex.response.reqId); + System.out.println(ex.response.statusCode); + assertNotNull(ex.response.reqId); + assertEquals(614, ex.response.statusCode); + } + } + } +} diff --git a/src/test/java/test/com/qiniu/streaming/StreamingTest.java b/src/test/java/test/com/qiniu/streaming/StreamingTest.java index 25ba03a6c..e3b49cac1 100644 --- a/src/test/java/test/com/qiniu/streaming/StreamingTest.java +++ b/src/test/java/test/com/qiniu/streaming/StreamingTest.java @@ -1,14 +1,11 @@ package test.com.qiniu.streaming; -import com.google.gson.JsonSyntaxException; import com.qiniu.common.QiniuException; import com.qiniu.streaming.StreamingManager; import com.qiniu.streaming.model.ActivityRecords; import com.qiniu.streaming.model.StreamAttribute; import com.qiniu.streaming.model.StreamListing; -import com.qiniu.streaming.model.StreamStatus; import com.qiniu.util.Auth; -import com.qiniu.util.Json; import org.junit.Test; import test.com.qiniu.TestConfig; @@ -16,82 +13,85 @@ /** * Created by bailong on 16/9/22 + * Updated by panyuan on 19/3/12 */ public class StreamingTest { + private Auth auth = TestConfig.testAuth; - private String hub = "pilisdktest"; - private String streamKeyPrefix = "pilijava" + System.currentTimeMillis(); + private String stream = "javasdk"; + private String streamNoExist = "javasdk" + "NoExist"; + private String streamKeyPrefix = "javasdk"; private StreamingManager manager = new StreamingManager(auth, hub); - - //@Test + /** + * 测试获取不存在的流的信息 + * 检测返回状态码是否是612 + */ + @Test public void testGetNoExistStream() { try { - manager.attribute("nnnoexist"); + manager.attribute(streamNoExist); fail("should not exist"); } catch (QiniuException e) { - e.printStackTrace(); assertEquals(612, e.code()); } } - // CHECKSTYLE:OFF - //@Test + /** + * 测试创建、禁用、启用、获取流信息、列举 + * @throws QiniuException + */ + @Test public void testStreamOperation() throws QiniuException { - // CHECKSTYLE:ON - String streamKey = streamKeyPrefix + "-a"; - - manager.create(streamKey); - - StreamAttribute attr = manager.attribute(streamKey); + StreamAttribute attr = manager.attribute(stream); assertEquals(0, attr.disabledTill); assertNotEquals(0, attr.createdAt); try { - manager.create(streamKey); + manager.create(stream); fail("has already existed"); } catch (QiniuException e) { assertEquals(614, e.code()); } - manager.disableTill(streamKey, -1); + manager.disableTill(stream, -1); - attr = manager.attribute(streamKey); + attr = manager.attribute(stream); assertEquals(-1, attr.disabledTill); assertNotEquals(0, attr.updatedAt); - manager.enable(streamKey); - attr = manager.attribute(streamKey); + manager.enable(stream); + attr = manager.attribute(stream); assertEquals(0, attr.disabledTill); assertNotEquals(0, attr.updatedAt); long t = System.currentTimeMillis() / 1000 + 3600; - manager.disableTill(streamKey, t); - attr = manager.attribute(streamKey); + manager.disableTill(stream, t); + attr = manager.attribute(stream); assertEquals(t, attr.disabledTill); assertNotEquals(0, attr.updatedAt); - manager.enable(streamKey); - attr = manager.attribute(streamKey); + manager.enable(stream); + attr = manager.attribute(stream); assertEquals(0, attr.disabledTill); assertNotEquals(0, attr.updatedAt); try { - StreamStatus status = manager.status(streamKey); + manager.status(stream); fail(); } catch (QiniuException e) { assertEquals(619, e.code()); } try { - manager.saveAs(streamKey, null, 0, 0); + manager.saveAs(stream, null, 0, 0); fail(); } catch (QiniuException e) { assertEquals(619, e.code()); } - ActivityRecords records = manager.history(streamKey, System.currentTimeMillis() / 1000 - 1000, 0); + ActivityRecords records = manager.history(stream, System.currentTimeMillis() / 1000 - 1000, 0); assertEquals(0, records.items.length); StreamListing l = manager.listStreams(false, streamKeyPrefix, null); @@ -118,34 +118,31 @@ public void testStreamOperation() throws QiniuException { assertFalse(it.hasNext()); } - //@Test + /** + * 测试saveas + * 检测返回状态码是否是404 + * @throws QiniuException + */ + @Test public void testSaveAs() throws QiniuException { try { - manager.saveAs("test--sd", "f\"ff.m3u8"); + manager.saveAs(streamNoExist, "f\"ff.m3u8"); } catch (QiniuException e) { - // 619 , no data; 612 stream not found, 但请求正常 // - if (e.code() != 619 && e.code() != 612) { - throw e; - } + assertEquals(404, e.response.statusCode); } } - //@Test + /** + * 测试创建流 + * 检测返回状态码是否为614 + * @throws QiniuException + */ + @Test public void testCreate() throws QiniuException { try { - String body = String.format("{\"key\":\"%s\"}", "stream\"Key"); - System.out.println(body); - Json.decode(body); - fail("json 解析不正确"); - } catch (JsonSyntaxException e) { - - } - try { - manager.create("streamKey"); + manager.create(stream); } catch (QiniuException e) { - if (e.code() != 614) { - throw e; - } + assertEquals(614, e.code()); } } From f9a354c060c6f10bd63486cdbf6bf067c3fd29ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=98=E6=BD=98?= Date: Wed, 13 Mar 2019 14:44:08 +0800 Subject: [PATCH 2/4] FormUpload With InputStream --- src/main/java/com/qiniu/util/IOUtils.java | 7 +++++++ src/test/java/test/com/qiniu/rtc/RtcTest.java | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/qiniu/util/IOUtils.java b/src/main/java/com/qiniu/util/IOUtils.java index 0f71b5e23..e56fd2248 100644 --- a/src/main/java/com/qiniu/util/IOUtils.java +++ b/src/main/java/com/qiniu/util/IOUtils.java @@ -8,6 +8,13 @@ public class IOUtils { private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + /** + * 输入InputSteam,返回byte[]. + * 参考:https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/IOUtils.java
+ * @param input + * @return + * @throws IOException + */ public static byte[] toByteArray(final InputStream input) throws IOException { try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; diff --git a/src/test/java/test/com/qiniu/rtc/RtcTest.java b/src/test/java/test/com/qiniu/rtc/RtcTest.java index d30ad78e4..256d62dd9 100644 --- a/src/test/java/test/com/qiniu/rtc/RtcTest.java +++ b/src/test/java/test/com/qiniu/rtc/RtcTest.java @@ -10,7 +10,6 @@ public class RtcTest { - private Auth auth = TestConfig.testAuth; private RtcAppManager manager = new RtcAppManager(auth); private RtcRoomManager rmanager = new RtcRoomManager(auth); From 313957f77a318fc7df7996936eb25e2804392499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=98=E6=BD=98?= Date: Wed, 13 Mar 2019 15:05:49 +0800 Subject: [PATCH 3/4] FormUpload With InputStream --- .../java/com/qiniu/storage/UploadManager.java | 38 ++++++++++++++----- .../com/qiniu/storage/FormUploadTest2.java | 4 +- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/qiniu/storage/UploadManager.java b/src/main/java/com/qiniu/storage/UploadManager.java index 6a12d48e4..1ce88799d 100644 --- a/src/main/java/com/qiniu/storage/UploadManager.java +++ b/src/main/java/com/qiniu/storage/UploadManager.java @@ -89,32 +89,50 @@ public void accept(String key, Object value) { } /** - * 上传字节流,表单形式 - * 合适小文件,大文件请用流式上传 + * 上传字节流,默认分片上传 * @param inputStream * @param key * @param token * @return * @throws QiniuException + * @throws IOException */ - public Response putWithForm(InputStream inputStream, String key, String token) throws QiniuException, IOException { - return putWithForm(inputStream, key, token, null, null, false); + public Response put(InputStream inputStream, String key, String token) throws QiniuException, IOException { + return put(inputStream, -1, key, token, null, null, false); } /** - * 上传字节流,表单形式 - * 合适小文件,大文件请用流式上传 + * 上传字节流,小文件走表单,大文件走分片 * @param inputStream + * @param size * @param key * @param token - * @param params - * @param mime - * @param checkCrc * @return * @throws QiniuException + * @throws IOException */ - public Response putWithForm(InputStream inputStream, String key, String token, StringMap params, + public Response put(InputStream inputStream, long size, String key, String token) throws QiniuException, IOException { + return put(inputStream, size, key, token, null, null, false); + } + + /** + * 上传字节流,小文件走表单,大文件走分片 + * @param inputStream + * @param size + * @param key + * @param token + * @param params + * @param mime + * @param checkCrc + * @return + * @throws QiniuException + * @throws IOException + */ + public Response put(InputStream inputStream, long size, String key, String token, StringMap params, String mime, boolean checkCrc) throws QiniuException, IOException { + if (size < 0 || size > configuration.putThreshold) { + return put(inputStream, key, token, params, mime); + } byte[] data = IOUtils.toByteArray(inputStream); return put(data, key, token, params, mime, checkCrc); } diff --git a/src/test/java/test/com/qiniu/storage/FormUploadTest2.java b/src/test/java/test/com/qiniu/storage/FormUploadTest2.java index 17d750299..32338a3fc 100644 --- a/src/test/java/test/com/qiniu/storage/FormUploadTest2.java +++ b/src/test/java/test/com/qiniu/storage/FormUploadTest2.java @@ -33,7 +33,7 @@ public void testFormUploadWithInputStream() { try { InputStream inputStream = new FileInputStream(TempFile.createFile(11)); - Response response = uploadManager.putWithForm(inputStream, TestConfig.testBucket_z0, token); + Response response = uploadManager.put(inputStream, TestConfig.testBucket_z0, token); System.out.println(response.reqId); System.out.println(response.statusCode); System.out.println(response.bodyString()); @@ -59,7 +59,7 @@ public void testFormUploadWithInputStreamWithPolicy() { try { InputStream inputStream = new FileInputStream(TempFile.createFile(11)); - uploadManager.putWithForm(inputStream, TestConfig.testBucket_z0, token); + uploadManager.put(inputStream, TestConfig.testBucket_z0, token); } catch (Exception e) { if (e instanceof QiniuException) { QiniuException ex = (QiniuException) e; From da89d794065cd2708baa135e5c0e2ac256d29704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=98=E6=BD=98?= Date: Wed, 13 Mar 2019 18:32:43 +0800 Subject: [PATCH 4/4] FormUpload With InputStream --- .../java/com/qiniu/storage/UploadManager.java | 27 ------- src/test/java/test/com/qiniu/TestConfig.java | 5 +- .../com/qiniu/storage/FormUploadTest.java | 42 +++++++++++ .../com/qiniu/storage/FormUploadTest2.java | 73 ------------------- 4 files changed, 44 insertions(+), 103 deletions(-) delete mode 100644 src/test/java/test/com/qiniu/storage/FormUploadTest2.java diff --git a/src/main/java/com/qiniu/storage/UploadManager.java b/src/main/java/com/qiniu/storage/UploadManager.java index 1ce88799d..c8911fba3 100644 --- a/src/main/java/com/qiniu/storage/UploadManager.java +++ b/src/main/java/com/qiniu/storage/UploadManager.java @@ -88,33 +88,6 @@ public void accept(String key, Object value) { return ret; } - /** - * 上传字节流,默认分片上传 - * @param inputStream - * @param key - * @param token - * @return - * @throws QiniuException - * @throws IOException - */ - public Response put(InputStream inputStream, String key, String token) throws QiniuException, IOException { - return put(inputStream, -1, key, token, null, null, false); - } - - /** - * 上传字节流,小文件走表单,大文件走分片 - * @param inputStream - * @param size - * @param key - * @param token - * @return - * @throws QiniuException - * @throws IOException - */ - public Response put(InputStream inputStream, long size, String key, String token) throws QiniuException, IOException { - return put(inputStream, size, key, token, null, null, false); - } - /** * 上传字节流,小文件走表单,大文件走分片 * @param inputStream diff --git a/src/test/java/test/com/qiniu/TestConfig.java b/src/test/java/test/com/qiniu/TestConfig.java index 17561d119..fd59b7692 100644 --- a/src/test/java/test/com/qiniu/TestConfig.java +++ b/src/test/java/test/com/qiniu/TestConfig.java @@ -2,7 +2,7 @@ import com.qiniu.util.Auth; -import test.com.qiniu.storage.FormUploadTest2; +import test.com.qiniu.storage.FormUploadTest; public final class TestConfig { @@ -46,10 +46,9 @@ public static boolean isTravis() { } public static void main(String[] args) { - FormUploadTest2 t = new FormUploadTest2(); try { + FormUploadTest t = new FormUploadTest(); t.testFormUploadWithInputStream(); - t.testFormUploadWithInputStreamWithPolicy(); System.out.println("done"); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/java/test/com/qiniu/storage/FormUploadTest.java b/src/test/java/test/com/qiniu/storage/FormUploadTest.java index 42cbc09b5..595f0cb7a 100644 --- a/src/test/java/test/com/qiniu/storage/FormUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/FormUploadTest.java @@ -14,6 +14,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -450,6 +451,47 @@ public void testFormLargeSize2() { } } } + + /** + * 测试inputStream 表单上传 + * 检测reqid是否为Null + * 检测状态码是否为200 + */ + @Test + public void testFormUploadWithInputStream() { + testFormUploadWithInputStream(1, -1); + testFormUploadWithInputStream(1, 0); + testFormUploadWithInputStream(1, 1000); + testFormUploadWithInputStream(4 * 1024, 4 * 1024 * 1024); + testFormUploadWithInputStream(5 * 1024, -1); + testFormUploadWithInputStream(5 * 1024, 5 * 1024 * 1024); + } + + /** + * 测试inputStream 表单上传 + * 检测reqid是否为Null + * 检测状态码是否为200 + */ + public void testFormUploadWithInputStream(long kiloSize, long size) { + + String token = TestConfig.testAuth.uploadToken(TestConfig.testBucket_z0, TestConfig.testBucket_z0, 3600, null); + System.out.println("token="+token); + + try { + File file = TempFile.createFile(kiloSize); + InputStream inputStream = new FileInputStream(file); + System.out.println("length=" + file.length()); + System.out.println("size=" + size); + Response response = uploadManager.put(inputStream, size, TestConfig.testBucket_z0, token, null, null, false); + System.out.println("code="+response.statusCode); + System.out.println("reqid="+response.reqId); + System.out.println(response.bodyString()); + assertNotNull(response.reqId); + assertEquals(200, response.statusCode); + } catch (Exception e) { + e.printStackTrace(); + } + } class MyRet { public String hash; diff --git a/src/test/java/test/com/qiniu/storage/FormUploadTest2.java b/src/test/java/test/com/qiniu/storage/FormUploadTest2.java deleted file mode 100644 index 32338a3fc..000000000 --- a/src/test/java/test/com/qiniu/storage/FormUploadTest2.java +++ /dev/null @@ -1,73 +0,0 @@ -package test.com.qiniu.storage; - -import java.io.FileInputStream; -import java.io.InputStream; - -import org.junit.Test; - -import com.qiniu.common.QiniuException; -import com.qiniu.http.Response; -import com.qiniu.storage.Configuration; -import com.qiniu.storage.UploadManager; -import com.qiniu.util.StringMap; - -import test.com.qiniu.TempFile; -import test.com.qiniu.TestConfig; - -import static org.junit.Assert.*; - -public class FormUploadTest2 { - - UploadManager uploadManager = new UploadManager(new Configuration()); - - /** - * 测试传入inputStream的表单上传 - * 检测reqid是否为Null - * 检测状态码是否为200 - */ - @Test - public void testFormUploadWithInputStream() { - - String token = TestConfig.testAuth.uploadToken(TestConfig.testBucket_z0, TestConfig.testBucket_z0, 3600, null); - System.out.println(token); - - try { - InputStream inputStream = new FileInputStream(TempFile.createFile(11)); - Response response = uploadManager.put(inputStream, TestConfig.testBucket_z0, token); - System.out.println(response.reqId); - System.out.println(response.statusCode); - System.out.println(response.bodyString()); - assertNotNull(response.reqId); - assertEquals(200, response.statusCode); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * 测试传入inputStream的表单上传 - * 检测reqid是否为Null - * 检测状态码是否为614 - */ - @Test - public void testFormUploadWithInputStreamWithPolicy() { - - StringMap putPolicy = new StringMap(); - putPolicy.put("insertOnly", 1); - String token = TestConfig.testAuth.uploadToken(TestConfig.testBucket_z0, TestConfig.testBucket_z0, 3600, putPolicy); - System.out.println(token); - - try { - InputStream inputStream = new FileInputStream(TempFile.createFile(11)); - uploadManager.put(inputStream, TestConfig.testBucket_z0, token); - } catch (Exception e) { - if (e instanceof QiniuException) { - QiniuException ex = (QiniuException) e; - System.out.println(ex.response.reqId); - System.out.println(ex.response.statusCode); - assertNotNull(ex.response.reqId); - assertEquals(614, ex.response.statusCode); - } - } - } -}