nestjs-gcloud-storage
nestjs-gcloud-storage copied to clipboard
Field names other than "file" seem to be broken
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 afile
orfiles
object to therequest
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.
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.