【发布时间】:2015-07-25 10:41:28
【问题描述】:
我正在尝试从预签名的 url 将图像上传到 S3 存储桶,它给出了 ssl 异常错误连接被对等方关闭
这是我的代码
public int upload(String filePath, URL url) {
Bitmap bm = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 90, bos);
byte[] fileBytes = bos.toByteArray();
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/octet-stream");
OutputStream output = connection.getOutputStream();
InputStream input = new ByteArrayInputStream(fileBytes);
byte[] buffer = new byte[4096];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
return connection.getResponseCode();
}
【问题讨论】:
标签: android amazon-s3 httpurlconnection