Skip to content

Commit 3d7292e

Browse files
committed
Merge branch 'master' of github.com:xxlabaza/feign-form
2 parents 22dafeb + 461ebac commit 3d7292e

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

feign-form/src/main/java/feign/form/multipart/AbstractWriter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ protected void writeFileMetadata (Output output, String name, String fileName, S
6666

6767
String fileContentType = contentType;
6868
if (fileContentType == null) {
69-
fileContentType = fileName != null
70-
? URLConnection.guessContentTypeFromName(fileName)
71-
: "application/octet-stream";
69+
if (fileName != null) {
70+
fileContentType = URLConnection.guessContentTypeFromName(fileName);
71+
}
72+
if (fileContentType == null) {
73+
fileContentType = "application/octet-stream";
74+
}
7275
}
7376

7477
val string = new StringBuilder()

feign-form/src/test/java/feign/form/BasicClientTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,13 @@ public void testUploadWithJson () throws Exception {
149149
Assert.assertNotNull(response);
150150
Assert.assertEquals(200, response.status());
151151
}
152+
153+
@Test
154+
public void testUnknownTypeFile() throws Exception {
155+
val path = Paths.get(this.getClass().getClassLoader().getResource("file.abc").toURI());
156+
Assert.assertTrue(Files.exists(path));
157+
158+
val stringResponse = api.uploadUnknownType(path.toFile());
159+
Assert.assertEquals("application/octet-stream", stringResponse);
160+
}
152161
}

feign-form/src/test/java/feign/form/Server.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,15 @@ public ResponseEntity<String> uploadByteArray (@RequestPart("file") MultipartFil
167167
: I_AM_A_TEAPOT;
168168
return ResponseEntity.status(status).body(file.getOriginalFilename());
169169
}
170+
171+
@PostMapping(
172+
path = "/upload/unknown_type",
173+
consumes = MULTIPART_FORM_DATA_VALUE
174+
)
175+
public ResponseEntity<String> uploadUnknownType (@RequestPart("file") MultipartFile file) {
176+
val status = file != null
177+
? OK
178+
: I_AM_A_TEAPOT;
179+
return ResponseEntity.status(status).body(file.getContentType());
180+
}
170181
}

feign-form/src/test/java/feign/form/TestClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ public interface TestClient {
6565
@RequestLine("POST /upload/with_json")
6666
@Headers("Content-Type: multipart/form-data")
6767
Response uploadWithJson (@Param("dto") Dto dto, @Param("file") File file);
68+
69+
@RequestLine("POST /upload/unknown_type")
70+
@Headers("Content-Type: multipart/form-data")
71+
String uploadUnknownType (@Param("file") File file);
6872
}

feign-form/src/test/resources/file.abc

Whitespace-only changes.

0 commit comments

Comments
 (0)