nestjs-gcloud-storage icon indicating copy to clipboard operation
nestjs-gcloud-storage copied to clipboard

Field names other than "file" seem to be broken

Open gdrbyKo1 opened this issue 3 years ago • 1 comments

Hi. It seems that custom field names don't work correctly with the interceptors. For example:

@UseInterceptors(
  GCloudStorageFileInterceptor('customField')
)

This will always result in the error

Can not intercept field "customField". Did you specify the correct field name in @GCloudStorageFileInterceptor('customField')?

The error originates from here: https://github.com/Aginix/nestjs-gcloud-storage/blob/42fe01120b841ab5256ba43ab6f8c660000ddb26/lib/gcloud-stroage-file.interceptor.ts#L26-L34 I think the line const file = request[fieldName]; is incorrect, as according to multer docs:

  • Multer adds a body object and a file or files object to the request object

But the interceptor tries to access a property of the request object based on the provided fieldName parameter. So GCloudStorageFileInterceptor('file') works, but everything else won't.

gdrbyKo1 avatar Mar 31 '21 10:03 gdrbyKo1

https://github.com/Aginix/nestjs-gcloud-storage/blob/42fe01120b841ab5256ba43ab6f8c660000ddb26/lib/gcloud-stroage-file.interceptor.ts#L20-L30

At line 26, the correct is:

    const file = request.file;

Because multer ALWAYS inserts a key "file" on request object.

klawdyo avatar Oct 25 '22 13:10 klawdyo