Skip to content

Commit a69f762

Browse files
committed
Merge pull request #187 from sxci/fix/form_fileName
fix: invalid multipart format: multipart: message too large
2 parents 8394480 + 2efce68 commit a69f762

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ private void buildParams() throws QiniuException {
8383
if (file != null) {
8484
fileName = file.getName();
8585
}
86+
if (fileName == null || fileName.trim().length() == 0) {
87+
fileName = "fileName";
88+
}
8689
if (checkCrc) {
8790
long crc32 = 0;
8891
if (file != null) {

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import com.qiniu.TempFile;
44
import com.qiniu.TestConfig;
5+
import com.qiniu.common.Config;
56
import com.qiniu.common.QiniuException;
67
import com.qiniu.http.Response;
78
import com.qiniu.util.StringMap;
89
import org.junit.Test;
910

1011
import java.io.File;
12+
import java.io.FileInputStream;
1113
import java.io.IOException;
1214
import java.util.concurrent.CountDownLatch;
1315
import java.util.concurrent.TimeUnit;
@@ -250,5 +252,60 @@ class MyRet {
250252
public String mimeType;
251253
}
252254

255+
// @Test
256+
public void testFormLargeSize() {
257+
Config.PUT_THRESHOLD = 25 * 1024 * 1024;
258+
259+
final String expectKey = "yyyyyy";
260+
File f = null;
261+
try {
262+
f = TempFile.createFile(Config.PUT_THRESHOLD / 1024 - 1);
263+
} catch (IOException e) {
264+
e.printStackTrace();
265+
}
266+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey);
267+
Response r = null;
268+
try {
269+
r = uploadManager.put(f, expectKey, token, null, null, false);
270+
} catch (QiniuException e) {
271+
try {
272+
assertEquals("_", e.response.bodyString());
273+
} catch (QiniuException e1) {
274+
e1.printStackTrace();
275+
}
276+
}
277+
278+
}
279+
280+
281+
// @Test
282+
public void testFormLargeSize2() {
283+
Config.PUT_THRESHOLD = 25 * 1024 * 1024;
284+
285+
final String expectKey = "xxxxxxx";
286+
byte[] bb = null;
287+
File f = null;
288+
try {
289+
f = TempFile.createFile(Config.PUT_THRESHOLD / 1024 - 1);
290+
bb = new byte[(int) (f.length())];
291+
FileInputStream fis = new FileInputStream(f);
292+
fis.read(bb, 0, (int) (f.length()));
293+
} catch (IOException e) {
294+
e.printStackTrace();
295+
}
296+
297+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey);
298+
Response r = null;
299+
try {
300+
r = uploadManager.put(bb, expectKey, token, null, null, false);
301+
} catch (QiniuException e) {
302+
try {
303+
assertEquals("_", e.response.bodyString());
304+
} catch (QiniuException e1) {
305+
e1.printStackTrace();
306+
}
307+
}
308+
309+
}
253310

254311
}

0 commit comments

Comments
 (0)