Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用预先签名的URL将文件上载到AWS S3_Jquery_Amazon Web Services_Amazon S3_Aws Lambda - Fatal编程技术网

Jquery 使用预先签名的URL将文件上载到AWS S3

Jquery 使用预先签名的URL将文件上载到AWS S3,jquery,amazon-web-services,amazon-s3,aws-lambda,Jquery,Amazon Web Services,Amazon S3,Aws Lambda,我有我的S3预先签署的网址工作良好,在邮递员和我可以上传图像到S3使用邮递员。我现在正试图让它从我自己的网页工作。我让jQuery检索预先签名的URL。问题是当我尝试将图像上传到S3时。我在Firefox浏览器中收到一个403禁止。非常感谢您的任何见解。以下是相关的HTML和jQuery代码: <form enctype='multipart/form-data' id="aws_upload_form" method='POST' > <input

我有我的S3预先签署的网址工作良好,在邮递员和我可以上传图像到S3使用邮递员。我现在正试图让它从我自己的网页工作。我让jQuery检索预先签名的URL。问题是当我尝试将图像上传到S3时。我在Firefox浏览器中收到一个403禁止。非常感谢您的任何见解。以下是相关的HTML和jQuery代码:

<form enctype='multipart/form-data' id="aws_upload_form" method='POST' >
   <input type='hidden' name='MAX_FILE_SIZE' value='1000000' />
   <input type='hidden' name='x-amz-acl' value='public-read' />
   <input type='file' id="fileInput" />
   <input type='submit' value='Upload Selected File To S3' />
</form>

谢谢你的帮助。

我刚把它修好。我补充说:

标题:{'x-amz-acl':'public read'},


在handleData函数的ajax调用中

我刚刚让它工作起来。我补充说:

标题:{'x-amz-acl':'public read'},


在handleData函数的ajax调用中

我刚刚让它工作起来。我在handleData函数中添加了标题:{'x-amz-acl':'public read'},ajax callI刚刚让它工作起来。我在handleData函数ajax调用中添加了标题:{'x-amz-acl':'public read'}
$(document).ready(function() {
    const apigw_endpt = "https://blahblah.execute-api.region.amazonaws.com/api";
    
    $("#aws_upload_form").submit(function (e) {
        e.preventDefault();
        var form_data = new FormData(this); //Creates new FormData object

        var selectedFile = document.getElementById('fileInput');
        var nameOfFile = selectedFile.files.item(0).name;

        if (nameOfFile.length > 0) {
            $("#selectedFile").html(nameOfFile);
            $.ajax({
                url: apigw_endpt + "/generate_presigned_url",
                data: {
                    file_name: nameOfFile
                },
                type: "GET",
                dataType : "json",
                success: function (json) {
                    handleData(json, form_data);
                },
                error: function( xhr, status, errorThrown ) {
                    jq_ui_alert( 'dialog-message', "Sorry, there was an AJAX problem with ..." );
                    console.log( "Error: " + errorThrown );
                    console.log( "Status: " + status );
                    console.dir( xhr );
                }
            });
        } else {
            alert("No File Selected");
        }
    });
});

function handleData(json, form_data) {
    $.ajax({
        url: json.fields,
        type: 'PUT',
        contentType: 'image/jpeg',
        data: form_data,
        processData: false
    });
}