如何在 java 中连接 CloudFront?

How to connect CloudFront in java?

目前,我正在使用 java API 通过 Amazon s3 SDK 将文档上传到 Amazon s3,但我想利用 CloudFront 的缓存设施来加快上传下载过程,这样可以有人给出了如何使用 Cloudfront 在 s3 中上传 file/image 的任何指示吗?

终于,我得到了答案。我正在使用 CloudFront Http 方法通过 CloudFront 在 S3 存储桶中上传 Image/Document。 这是我的代码

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();
    }