@henna.s Please see the attached code
// arg = [["key(filename)", "filetype"]]
exports = async function(arg){
const S3 = require('aws-sdk/clients/s3');
console.log(arg)
const AWSAccessKeyID = context.values.get("AWSAccessKeyID_value");
const AWSSecretKey = context.values.get("AWSSecretKey_value");
// Configuring AWS
const s3 = new S3({
accessKeyId: AWSAccessKeyID, // stored in the .env file
secretAccessKey: AWSSecretKey, // stored in the .env file
region: "us-east-1",
});
// retrieve the bucket name
const Bucket = "";
// PUT URL Generator
const generatePutUrl = (Key, ContentType) => {
return new Promise((resolve, reject) => {
// Note Bucket is retrieved from the env variable above.
const params = { Bucket, Key, ContentType, Expires: 900 };
// Note operation in this case is putObject
s3.getSignedUrl('putObject', params, function(err, url) {
if (err) {
reject(err);
}
// If there is no errors we can send back the pre-signed PUT URL
resolve(url);
});
});
}
const URLS = await Promise.all(arg.map((res, index) => {
const awaitresult = generatePutUrl(res[0], res[1])
return awaitresult
}));
return {urls: URLS};
};