Skip to content

Commit 89d3bbb

Browse files
author
Jevgeni Koltšin
committed
added content type to S3 upload request
1 parent 01de14b commit 89d3bbb

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/main/java/com/creatubbles/api/request/amazon/UploadS3ImageRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public CreatubblesRequest<UploadS3ImageResponse> execute() {
3232
resetResponse();
3333
UploadS3ImageResponse response = new UploadS3ImageResponse();
3434
try {
35-
response.success = isSuccessStatusCode(HttpUtil.uploadObject(data, url));
35+
response.success = isSuccessStatusCode(HttpUtil.uploadObject(data, url, HttpUtil.IMAGE_JPEG_CONTENT_TYPE));
3636
setResponseCache(response);
3737
} catch (IOException e) {
3838
e.printStackTrace();

src/main/java/com/creatubbles/api/util/HttpUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
public class HttpUtil {
1010

11-
public static int uploadObject(byte[] data, String url) throws IOException {
11+
public static final String IMAGE_JPEG_CONTENT_TYPE = "image/jpeg";
12+
13+
public static int uploadObject(byte[] data, String url, String contentType) throws IOException {
1214
HttpURLConnection connection = (HttpURLConnection) (new URL(url).openConnection());
1315
connection.setDoOutput(true);
1416
connection.setUseCaches(false);
1517
connection.setRequestMethod(HttpMethod.PUT.name());
18+
connection.setRequestProperty("Content-Type", contentType);
1619
OutputStream out = connection.getOutputStream();
1720
ByteArrayInputStream in = new ByteArrayInputStream(data);
1821
byte[] buffer = new byte[4096];

0 commit comments

Comments
 (0)