1 回答
TA贡献1824条经验 获得超6个赞
最后,我得到了答案。我正在使用 CloudFront Http 方法通过 CloudFront 在 S3 存储桶中上传图像/文档。这是我的代码
URL url;
try {
url = new URL("**cloudfront URL***"+imagePath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset","UTF-8");
connection.setRequestProperty("Content-Length",imageByteArray.length+"");
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.write(imageByteArray);
wr.flush();
wr.close();
connection.disconnect();
// Check the HTTP response code. To complete the upload and make the object available,
// you must interact with the connection object in some way.
connection.getResponseCode();
System.out.println("HTTP response code: " + connection.getResponseCode());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
添加回答
举报