我正在开发一项功能,使用 Angular/presigned url 和 API Gateway/Lambda 将文件上传到 S3,以生成预签名 url。
我的工作流程描述如下:
const body = { fileName: this.selectedFile.name } const preSignedUrl = await this.http.post('https://xxxxx.execute-api.eu-west-1.amazonaws.com/dev/v1/profile/avatar ', body).toPromise();
后端
我正在使用无服务器(Lambda/API 网关)来计算 presignedUrl。
拉姆达
const AWS = require('aws-sdk')
module.exports.uploadLargeFile = async (event) => {
console.log('1. Event: ', event.body);
const reqBodyAsString = event.body || '{}';
const fileName = JSON.parse(reqBodyAsString).fileName;
return getUploadURL(fileName);
}
const getUploadURL = async (fileName) => {
const s3Params = {
Bucket: process.env.AVATAR_BUCKET,
Expires: 60 …Run Code Online (Sandbox Code Playgroud) file-upload amazon-s3 amazon-web-services pre-signed-url angular