Skip to content

Commit da89d79

Browse files
缘潘缘潘
authored andcommitted
FormUpload With InputStream
1 parent 313957f commit da89d79

File tree

4 files changed

+44
-103
lines changed

4 files changed

+44
-103
lines changed

src/main/java/com/qiniu/storage/UploadManager.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,6 @@ public void accept(String key, Object value) {
8888
return ret;
8989
}
9090

91-
/**
92-
* 上传字节流,默认分片上传
93-
* @param inputStream
94-
* @param key
95-
* @param token
96-
* @return
97-
* @throws QiniuException
98-
* @throws IOException
99-
*/
100-
public Response put(InputStream inputStream, String key, String token) throws QiniuException, IOException {
101-
return put(inputStream, -1, key, token, null, null, false);
102-
}
103-
104-
/**
105-
* 上传字节流,小文件走表单,大文件走分片
106-
* @param inputStream
107-
* @param size
108-
* @param key
109-
* @param token
110-
* @return
111-
* @throws QiniuException
112-
* @throws IOException
113-
*/
114-
public Response put(InputStream inputStream, long size, String key, String token) throws QiniuException, IOException {
115-
return put(inputStream, size, key, token, null, null, false);
116-
}
117-
11891
/**
11992
* 上传字节流,小文件走表单,大文件走分片
12093
* @param inputStream

src/test/java/test/com/qiniu/TestConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.qiniu.util.Auth;
44

5-
import test.com.qiniu.storage.FormUploadTest2;
5+
import test.com.qiniu.storage.FormUploadTest;
66

77
public final class TestConfig {
88

@@ -46,10 +46,9 @@ public static boolean isTravis() {
4646
}
4747

4848
public static void main(String[] args) {
49-
FormUploadTest2 t = new FormUploadTest2();
5049
try {
50+
FormUploadTest t = new FormUploadTest();
5151
t.testFormUploadWithInputStream();
52-
t.testFormUploadWithInputStreamWithPolicy();
5352
System.out.println("done");
5453
} catch (Exception e) {
5554
e.printStackTrace();

src/test/java/test/com/qiniu/storage/FormUploadTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.File;
1515
import java.io.FileInputStream;
1616
import java.io.IOException;
17+
import java.io.InputStream;
1718
import java.util.HashMap;
1819
import java.util.Map;
1920
import java.util.concurrent.CountDownLatch;
@@ -450,6 +451,47 @@ public void testFormLargeSize2() {
450451
}
451452
}
452453
}
454+
455+
/**
456+
* 测试inputStream 表单上传
457+
* 检测reqid是否为Null
458+
* 检测状态码是否为200
459+
*/
460+
@Test
461+
public void testFormUploadWithInputStream() {
462+
testFormUploadWithInputStream(1, -1);
463+
testFormUploadWithInputStream(1, 0);
464+
testFormUploadWithInputStream(1, 1000);
465+
testFormUploadWithInputStream(4 * 1024, 4 * 1024 * 1024);
466+
testFormUploadWithInputStream(5 * 1024, -1);
467+
testFormUploadWithInputStream(5 * 1024, 5 * 1024 * 1024);
468+
}
469+
470+
/**
471+
* 测试inputStream 表单上传
472+
* 检测reqid是否为Null
473+
* 检测状态码是否为200
474+
*/
475+
public void testFormUploadWithInputStream(long kiloSize, long size) {
476+
477+
String token = TestConfig.testAuth.uploadToken(TestConfig.testBucket_z0, TestConfig.testBucket_z0, 3600, null);
478+
System.out.println("token="+token);
479+
480+
try {
481+
File file = TempFile.createFile(kiloSize);
482+
InputStream inputStream = new FileInputStream(file);
483+
System.out.println("length=" + file.length());
484+
System.out.println("size=" + size);
485+
Response response = uploadManager.put(inputStream, size, TestConfig.testBucket_z0, token, null, null, false);
486+
System.out.println("code="+response.statusCode);
487+
System.out.println("reqid="+response.reqId);
488+
System.out.println(response.bodyString());
489+
assertNotNull(response.reqId);
490+
assertEquals(200, response.statusCode);
491+
} catch (Exception e) {
492+
e.printStackTrace();
493+
}
494+
}
453495

454496
class MyRet {
455497
public String hash;

src/test/java/test/com/qiniu/storage/FormUploadTest2.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)