首页 > 解决方案 > 使用预签名 URL 将对象上传到 AWS S3

问题描述

我想通过 dropzone 在 s3 存储桶中上传大文件。

我通过 Ajax 函数中的 RESTful api(预签名 URL PutObject)获得预签名 URL。

PHP ajax 函数代码:

$API_url = api_url;
$IdToken = $this->cognitoClient->getTokenIdCookie();
$curl = curl_init();
curl_setopt_array(
    $curl, 
    array(
        CURLOPT_URL => $API_url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HTTPHEADER => array(
            'Authorization: '.$IdToken
        ),
    )
);
$response = curl_exec($curl);
curl_close($curl);
$response_data = json_decode($response);
$presigned_url= $response_data->url;
return $this->json(
    array(
        "presigned_url"=>$presigned_url
    )
);

我想使用这个预签名的 URL 分段上传对象并跟踪其进度。

我已经查看了 javascript 中的“上传”功能,但我不知道如何将预签名的 url 与这个一起使用

标签: phpajaxamazon-s3aws-api-gatewayput

解决方案


推荐阅读