Nestjs this.minioClientService.upload 不是函数
Nestjs this.minioClientService.upload is not a function
这是我的 minio-client.service:
@Injectable()
export class MinioClientService {
private readonly logger = new Logger(MinioClientService.name);
private readonly defaultBucketName = 'default';
constructor(private minio: Minio.Client) {}
async upload(
file: Express.Multer.File,
bucketName: string = this.defaultBucketName,
) {
// some code & logic
}
}
我在 admins.service:
中导入了上述服务
@Injectable()
export class AdminsService {
constructor(
@InjectRepository(AdminsRepository)
// this line
private minioClientService: MinioClientService,
private adminsRepository: AdminsRepository,
) {}
async update(file) {
if (file) {
// error happens here
const uploadedImage = await this.minioClientService.upload(file);
console.log(uploadedImage);
}
}
和错误信息:
我还在admins.moudle中导入了minio-client.module,启动应用程序时没有报错。调用此 update 方法时发生错误。
您的 @InjectRepository()
装饰器用错了位置。该装饰器现在告诉 Nest 为应该为 MinioClientService
的参数注入 AdminsRepository
,但这超出了 Typescript 可以读取的范围。将其用于您的构造函数
constructor(
// this line
private minioClientService: MinioClientService,
@InjectRepository(AdminsRepository)
private adminsRepository: AdminsRepository,
) {}
它应该工作得很好。
这是我的 minio-client.service:
@Injectable()
export class MinioClientService {
private readonly logger = new Logger(MinioClientService.name);
private readonly defaultBucketName = 'default';
constructor(private minio: Minio.Client) {}
async upload(
file: Express.Multer.File,
bucketName: string = this.defaultBucketName,
) {
// some code & logic
}
}
我在 admins.service:
中导入了上述服务@Injectable()
export class AdminsService {
constructor(
@InjectRepository(AdminsRepository)
// this line
private minioClientService: MinioClientService,
private adminsRepository: AdminsRepository,
) {}
async update(file) {
if (file) {
// error happens here
const uploadedImage = await this.minioClientService.upload(file);
console.log(uploadedImage);
}
}
和错误信息:
我还在admins.moudle中导入了minio-client.module,启动应用程序时没有报错。调用此 update 方法时发生错误。
您的 @InjectRepository()
装饰器用错了位置。该装饰器现在告诉 Nest 为应该为 MinioClientService
的参数注入 AdminsRepository
,但这超出了 Typescript 可以读取的范围。将其用于您的构造函数
constructor(
// this line
private minioClientService: MinioClientService,
@InjectRepository(AdminsRepository)
private adminsRepository: AdminsRepository,
) {}
它应该工作得很好。