Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field names other than "file" seem to be broken #379

Open
gdrbyKo1 opened this issue Mar 31, 2021 · 1 comment
Open

Field names other than "file" seem to be broken #379

gdrbyKo1 opened this issue Mar 31, 2021 · 1 comment

Comments

@gdrbyKo1
Copy link

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:

const file = request[fieldName];
if (!file) {
Logger.error(
'GCloudStorageFileInterceptor',
`Can not intercept field "${fieldName}". Did you specify the correct field name in @GCloudStorageFileInterceptor('${fieldName}')?`,
);
return;
}

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.

@klawdyo
Copy link

klawdyo commented Oct 25, 2022

}
async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>> {
(await this.interceptor.intercept(context, next)) as Observable<any>;
const request = context.switchToHttp().getRequest();
const file = request[fieldName];
if (!file) {
Logger.error(
'GCloudStorageFileInterceptor',

At line 26, the correct is:

    const file = request.file;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants