![](/img/trans.png)
[英]How to upload file to s3 through nodejs express from Angularjs
[英]File Upload to S3 through Ajax
我無法在S3中上傳文件。 我正在使用ajax調用,如下所示,
var fd = new FormData();
fd.append("file",file_input.files[0])
$.ajax({
url: "https://xxxxxxxxxxxxxx.execute-api.ap-xxxx-2.amazonaws.com/xxx/xxx",
type: 'POST',
data: fd,
headers: { "X-API-KEY": apikey},
contentType: false,
processType: false,
success: function(data)
{
if(data['result'] === "true")
{
$('#issue-error').text('Your report has been submitted successfully.');
$('#issue-error').css('color','green').show();
$('form').find("input[type=text], textarea").val("");
}
},
});
在此,URL是具有Python編寫的帶lamda函數的AWS API。 我無法傳遞文件參數本身。 普通參數我可以開機自檢,但不能發送文件。
我需要幫助。 謝謝
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>*</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
將其放入S3中的存儲桶配置中。
我更喜歡使用aws javascript sdk將文件上傳到aws,
AWS.config.credentials = { accessKeyId: "xxxxxxxxxx", secretAccessKey: "xxxxxxxxxxxxxx" }
AWS.config.region = 'us-west-2';
var bucket = new AWS.S3({params: {Bucket: 'bucket-name/folder-name'}});
var file = fileChooser.files[0];
if (file) {
var params = {
Key: "example.png",
ContentType: file.type,
Metadata: {
"security-key": "xxxxxxxxxxx"
} ,
Body: file
};
bucket.upload(params, function (err, data) {
console.log("file uploaded successfully");
});
} else {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.