Getting build error after upgrading @uppy/aws-s3

Started by manojattal2 replies1,097 views
manojattalOriginal post
#1

Hello,

We are using uppy uploader in our react code to handle file uploading to s3. Currently our code makes use of 3.1.1 version of @uppy/aws-s3

But when we upgrade it to 3.2.0 or any other higher version, we are getting an error while building the react code.

Here is the partial code from tsx file. The code breaks on line getUploadParameters

useAwsS3(props: IProps) {
        this.uppy.use(AwsS3, {
            getUploadParameters: (file) => {
                return PD.Shared.Ajax.post<string>(props.getPreSignedUrl, {
                    fileName: file.name,
                    contentType: file.type
                })
                    .then(data => {
                        return {
                            method: "put",
                            url: data,
                            fields: {},
                            headers: {
                                'Content-Type': file.type,
                            },
                        };
                    });
            }
        });        
    }

We are getting following error when we try to build react project.

TS2322: Type '(file: UppyFile<Record<string, unknown>, Record<string, unknown>>) => Promise<{ method?: "POST"; url: string; fields?: Record<string, string>; expires?: number; headers?: Record<...>; } | { ...; } | { ...; }>' is not assignable to type '((file: UppyFile<Record<string, unknown>, Record<string, unknown>>) => MaybePromise<AwsS3UploadParameters>) | ((file: UppyFile<Record<...>, Record<...>>) => MaybePromise<...>)'.
  Type '(file: UppyFile<Record<string, unknown>, Record<string, unknown>>) => Promise<{ method?: "POST"; url: string; fields?: Record<string, string>; expires?: number; headers?: Record<...>; } | { ...; } | { ...; }>' is not assignable to type '(file: UppyFile<Record<string, unknown>, Record<string, unknown>>) => MaybePromise<AwsS3UploadParameters>'.
    Type 'Promise<{ method?: "POST"; url: string; fields?: Record<string, string>; expires?: number; headers?: Record<string, string>; } | { method?: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<...>; } | { ...; }>' is not assignable to type 'MaybePromise<AwsS3UploadParameters>'.
      Type 'Promise<{ method?: "POST"; url: string; fields?: Record<string, string>; expires?: number; headers?: Record<string, string>; } | { method?: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<...>; } | { ...; }>' is not assignable to type 'Promise<AwsS3UploadParameters>'.
        Type '{ method?: "POST"; url: string; fields?: Record<string, string>; expires?: number; headers?: Record<string, string>; } | { method?: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<...>; } | { ...; }' is not assignable to type 'AwsS3UploadParameters'.
          Type '{ method?: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<string, string>; }' is not assignable to type 'AwsS3UploadParameters'.
            Type '{ method?: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<string, string>; }' is not assignable to type '{ method: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<string, string>; }'.
              Property 'method' is optional in type '{ method?: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<string, string>; }' but required in type '{ method: "PUT"; url: string; fields?: Record<string, never>; expires?: number; headers?: Record<string, string>; }'.
     96 |     useAwsS3(props: IProps) {
     97 |         this.uppy.use(AwsS3, {
  >  98 |             getUploadParameters: (file) => {
        |             ^^^^^^^^^^^^^^^^^^^
     99 |                 return PD.Shared.Ajax.post<string>(props.getPreSignedUrl, {
    100 |                     fileName: file.name,
    101 |                     contentType: file.type

Probably the issue seems to be related to this PR.
Can you someone give an idea about how to fix this?

manojattalReplying to #2
#3

Thanks @Merlijn for the quick reply!
Sure, I will setup dev env for Uppy and will give it a try to fix this.