无法使用带有s3的预签名URL的AJAX PUT请求获取上载的文件-jQuery

时间:2020-07-06 14:40:18

标签: jquery ajax amazon-s3 put

下面是我编写的代码:

JS:

$(function() {
            $('#theForm').on('submit', sendFile);
        });

        function sendFile(e) {
            e.preventDefault();

            // get the reference to the actual file in the input
            var theFormFile = $('#theFile').get()[0].files[0];

            $.ajax({
                type: 'PUT',
                url: 'MY PRESIGNED URL HERE',
                dataType : 'jsonp',   
                crossDomain:true,
                contentType: false,
                headers: {'Content-Type': 'multipart/form-data'},
                processData: false,
                data: theFormFile,

                error: function () {
                    alert('File NOT uploaded');
                },
                success: function () {
                    alert('File uploaded');
                }
            })
        };

HTML代码:

<form id="theForm" method="POST" enctype="multipart/form-data" >
   <input id="theFile" name="file" type="file"/>
   <button id="theButton" type="submit" class="upload-current-resume-linkedin btn-success">Upload</button>
</form>

输出: AJAX每次都会出错。 “文件未上传”

请指导我以上代码中需要进行哪些纠正。

0 个答案:

没有答案