亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何用java連接CloudFront?

如何用java連接CloudFront?

蝴蝶刀刀 2023-09-27 10:29:00
目前,我正在使用 java API 使用 Amazon s3 SDK 將文檔上傳到 Amazon s3,但我想利用 CloudFront 的緩存設施來加速上傳下載過程,因此任何人都可以提供有關如何在 s3 中上傳文件/圖像的任何指示使用云前端?
查看完整描述

1 回答

?
慕妹3242003

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

    }


查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號