jeffminsungkim / nestjs-multer-extended

💪 Extended MulterModule for NestJS with flexible S3 upload and helpful features
MIT License
202 stars 47 forks source link

Cannot read property 'storageOpts' of undefined #171

Closed mubasshir closed 4 years ago

mubasshir commented 4 years ago
TypeError: Cannot read property 'storageOpts' of undefined
    at MixinInterceptor.pickStorageOptions (/project/node_modules/nestjs-multer-extended/dist/interceptors/amazon-s3-file.interceptor.js:68:112)
    at MixinInterceptor.<anonymous> (/project/node_modules/nestjs-multer-extended/dist/interceptors/amazon-s3-file.interceptor.js:42:48)
    at Generator.next (<anonymous>)
    at /project/node_modules/nestjs-multer-extended/dist/interceptors/amazon-s3-file.interceptor.js:20:71
    at new Promise (<anonymous>)
    at __awaiter (/project/node_modules/nestjs-multer-extended/dist/interceptors/amazon-s3-file.interceptor.js:16:12)
    at MixinInterceptor.intercept (/project/node_modules/nestjs-multer-extended/dist/interceptors/amazon-s3-file.interceptor.js:39:20)
    at /project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:22:36
    at Object.handle (/project/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:20:56)
    at CacheInterceptor.intercept (/project/node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js:19:25)

Did I miss anything?

jeffminsungkim commented 4 years ago

Can you please show me how you imported the module?

mubasshir commented 4 years ago

app.module.ts

MulterExtendedModule.registerAsync({
      useFactory: (config: ConfigService) => config.get('s3'),
      inject: [ConfigService],
    }),

config/s3.ts

export default {
    accessKeyId: process.env.S3_ACCESS_KEY,
    secretAccessKey: process.env.S3_ACCESS_SECRET,
    region: process.env.S3_REGION,
    bucket: process.env.S3_BUCKET,
    fileSize: +process.env.S3_MAX_FILE_LIMIT * 1024 * 1024,
    acl: 'public-read',
};

users.controller.ts

  @Post('upload')
  @UseInterceptors(AmazonS3FileInterceptor('avatar', {
    dynamicPath: 'profile',
    randomFilename: true,
  }))
  async uploadFile(@Body() params, @UploadedFile() file): Promise<string> {
    params.avatar = file.location;
    return await this.service.upload(params);
  }
jeffminsungkim commented 4 years ago

Could you please show me the entire code from a app.module.ts file?

mubasshir commented 4 years ago
@Module({
  imports: [
    ConfigModule,
    ConfigModule.load(
      path.resolve(__dirname, 'config', '**', '!(*.d).{ts,js}'),
      {
        path: path.resolve(process.cwd(), 'env', !ENV ? '.env' : `.env.${ENV}`),
      },
    ),
    TypeOrmModule.forRootAsync({
      useFactory: (config: ConfigService) => config.get('database'),
      inject: [ConfigService],
    }),
    MulterExtendedModule.registerAsync({
      useFactory: (config: ConfigService) => config.get('s3'),
      inject: [ConfigService],
    }),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register(JWT_MODULE_OPTIONS),
    CacheModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (config: ConfigService) => config.get('cache'),
      inject: [ConfigService],
    }),
    HttpModule,
    ...
],
})
export class AppModule { }
jeffminsungkim commented 4 years ago

You should import the MulterExtendedModule on the same level where the controller wants to use it. (Solved it from VS Live Share)

mubasshir commented 4 years ago

thank you @jeffminsungkim , you were very kind & helpful

Utzel-Butzel commented 3 years ago

Sorry, I was unable to resolve the issue. Can you please explain what is meant by importing MulterExtendedModule on the same level where the controller is? Many thanks for the package and all your work!

premdasvm commented 2 years ago

Sorry, I was unable to resolve the issue. Can you please explain what is meant by importing MulterExtendedModule on the same level where the controller is? Many thanks for the package and all your work!

Were you able to fix this issue.?

premdasvm commented 2 years ago

thank you @jeffminsungkim , you were very kind & helpful

Hey mate, How did he fix it.?