Looking for a solution to upload files to a specific S3 object (folder) within an S3 bucket. My application relies on a single S3 bucket with objects (folders) that represent specific jobs and within those job folders reside additional objects (folders) containing .PDF files associated with a specific Asset ID. I would like to create an upload utility that requires the user to select job and asset aliases from dropdowns, and for those selected key value pairs pass in the job id and asset id into the S3 bucket referenced in the upload utility, analogous to building a file path. I can't seem to determine if this is possible for one, and for two I am not sure how to construct the Bucket Name in the S3 resource. I am envisioning something like this:{{ S3BucketName + / + Select1.selectedItem.JobId + / + Select2.selectedItem.AssetId }} to construct the "file path" to the specific S3 object where I wish to upload the file. Is this possible and if so how would I properly script the Bucket Name? Many thanks in advance!
hey @Miah2877 yeah you can construct the key for the object dynamically and pass it into the S3 resource (action="Upload data").
personally, for more than one join, i like string interpolation:
const bucket = {{transformerS3BucketName.value}}
const key = `${select1.selectedItem.jobId}/${select2.selectedItem.assetId}`
below here i am using variables for bucket, key, and MIME type, which will all be passed in by invoking <query name>.trigger()
method using additionalScope
parameter:
and then here is the JS query for looping over files and uploading them as objects to S3:
const trzFilename = trzFilenames.value[i]
let d = {
key: `${bucket_prefix.value}${trzFilename}`, -- string interpolation here
mime_type: f.type,
};
d.data = fileDropzone1.value[iCarousel].base64Data
const p = new Promise((resolve) => {
upload.trigger({
additionalScope: d, -- s3 query variables passed in here
onSuccess: (data) => {
count++;
resolve(data);
}
});
});
...
for your example case of a single upload, doing the interpolation within {{ }}
inside the S3 query itself makes more sense but just showing what I had lying around
Awesome thanks for the detailed direction!
1 Like