aws-sdk-js-codemod icon indicating copy to clipboard operation
aws-sdk-js-codemod copied to clipboard

[Feature]: support transformation of AWS.S3.ManagedUpload

Open jcable opened this issue 2 years ago • 2 comments
trafficstars

Self-service

  • [ ] I'd be willing to implement this feature

Problem

When running: npx aws-sdk-js-codemod -t v2-to-v3 example.js I get: Processing 1 files... Spawning 1 workers... Sending 1 files to free worker... All done. Results: 0 errors 1 unmodified 0 skipped 0 ok Time elapsed: 0.340seconds

import AWS from 'aws-sdk';
import { getUploadCredentials } from './boatregisterposts';

export async function postPhotos(values, fileList) {
    if (fileList?.length > 0) {
        try {
            const r = await getUploadCredentials();
            const uploadConfig = r.data;
            AWS.config.update({
                region: uploadConfig.region,
                credentials: new AWS.CognitoIdentityCredentials({
                    IdentityPoolId: `${uploadConfig.region}:${uploadConfig.identityId}`,
                })
            });
            const uploads = fileList.map((file) => {
                const photoKey = `${values.email}/${file.name}`;
                const params = {
                    Bucket: uploadConfig.bucketName,
                    Key: photoKey,
                    ContentType: file.type,
                    Body: file,
                    Metadata: {
                        albumKey: values.albumKey,
                        copyright: values.copyright,
                    },
                };
                return new AWS.S3.ManagedUpload({ params }).promise();
            });
            return Promise.allSettled(uploads);
        } catch (e) {
            // console.log(e);
        }
    }
    return undefined;
}

Solution

I want a working v3

Alternatives

n/a

Additional context

No response

jcable avatar Jun 02 '23 06:06 jcable

The AWS.S3.ManagedUpload is replace by Upload in v3. The service is renamed to client, and is no longer optional.

We added transformations for s3.upload in v0.12.0. As a workaround, you can change AWS.S3.ManagedUpload API to s3.upload and run codemod, while implementation for ManagedUpload is prioritized.

trivikr avatar Nov 02 '23 15:11 trivikr

https://github.com/strapi/strapi/blob/d482633e774699cc8d4e05531deaeb6001e791cd/packages/providers/upload-aws-s3/src/index.ts#L90

trivikr avatar Nov 02 '23 21:11 trivikr