作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从预签名的 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();
}
最佳答案
终于明白了这是使用预签名 URL 将图像发送到 S3 的代码
try {
Bitmap bm = BitmapFactory.decodeFile(fileBytes);
connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", "application/octet-stream"); // Very important ! It won't work without adding this!
OutputStream output = connection.getOutputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 50, output);
output.flush();
int response = connection.getResponseCode();
return connection.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
}
关于android - 如何使用来自 aws S3 服务器的 presignedurl 在 android 中上传图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31625600/
我正在使用 HttpVerb 生成预签名 URL 作为 PUT 以将文件上传到我的存储桶。奇怪的是,当我使用 AWSSDK 使用预置 URL 上传文件时,它工作正常。但是,当我在表单操作方法中使用此
我正在使用 aws-sdk-php 创建预签名 URL,用于将文件上传到 S3 存储桶。 GET 的 URL 正在运行。 这是代码 $client = S3Client::factory(array(
我正在尝试从预签名的 url 将图像上传到 S3 存储桶,它给出了 ssl 异常错误连接被对等方关闭 这是我的代码 public int upload(String filePath, URL url
我是一名优秀的程序员,十分优秀!