目前,我正在使用java来使用将文档上传到s3,但是我希望利用Cloudfront的缓存功能来加快上传下载过程,因此任何人可以给出如何使用CloudFront在s3中上传文件/图像的指针吗?
发布于 2019-10-05 20:49:20
最后,我得到了答案。我使用CloudFront Http方法在S3桶中通过CloudFront上传图像/文档。这是我的密码
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();
}https://stackoverflow.com/questions/58230045
复制相似问题