aginix / nestjs-gcloud-storage Goto Github PK
View Code? Open in Web Editor NEWGoogle Cloud Storage Module for Nest.js Framework
License: MIT License
Google Cloud Storage Module for Nest.js Framework
License: MIT License
Given this way of importing the module:
@Module({
controllers: [MyController],
imports: [
ConfigService,
GCloudStorageModule.withConfigAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
defaultBucketname: configService.get<string>(
'gcsConfig.defaultBucketname'
),
credentials: configService.get<IGCloudCredentials>(
'gcsConfig.credentials'
),
prefix: configService.get<string>('gcsConfig.prefix'),
projectId: configService.get<string>('gcsConfig.projectId')
}),
imports: [ConfigModule]
})
]
})
export class MyModule {}
I'm getting the following errors:
TypeError: Cannot read property 'defaultBucketname' of undefined
at new GCloudStorageService (/<PROJECT_PATH>/node_modules/@aginix/nestjs-gcloud-storage/dist/gcloud-storage.service.js:37:41)
as if the storage options are undefined.
Strange this is that if if set defaultBucketname: undefined
I then get the following, different, error:
Error: A bucket name is needed to use Cloud Storage.
I've tried hardcoding the configuration directly in the GCloudStorageFileInterceptor
parameters and everything works, so I guess it's an issue with withConfigAsync
.
I'm currently trying to investigate, but I can't seem to find any apparent reason for this issue to be happening.
If you want to resize the file before the upload, you can pass on the resize property as follows:
@post('upload')
@UseInterceptors(
GCloudStorageFileInterceptor('file', {
resize: { width: 500, height: 400 },
}),
)
uploadFile(@uploadedfile() file) {
console.log(file);
}
You can pass an array of size options to resize a single image into different sizes as follows:
@post('upload')
@UseInterceptors(
GCloudStorageFileInterceptor('file', {
resizeMultiple: [
{ suffix: 'sm', width: 200, height: 200 },
{ suffix: 'md', width: 300, height: 300 },
{ suffix: 'lg', width: 400, height: 400 },
],
}
)
uploadFile(@uploadedfile() file) {
console.log(file);
}
Throwing the above exception while trying to upload a PNG into a public bucket.
Hi just want to propose some minor changes if you can support uuid naming out of the box when uploading a file?
For example:
@post('upload')
@UseInterceptors(
GCloudStorageFileInterceptor('file', {
randomFilename: true
}),
)
uploadFile(@uploadedfile() file: UploadedFileMetadata) {
console.log(file);
}
You may want to store the file with an arbitrary name instead of the original file name. You can do this by passing the randomFilename property attribute set to true as follows:
I have a form to upload two images with different names say 'avatar' and 'background'
When i use
GCloudStorageFileInterceptor('background', undefined, {
prefix: 'background',
predefinedAcl: 'private'
}),
GCloudStorageFileInterceptor('avatar', undefined, {
prefix: 'avatar',
predefinedAcl: 'private'
}),
I get Unexpected field
error
@nestjs/platform-express
supports has FileFieldsInterceptor
which can take multiple fields
@UseInterceptors(FileFieldsInterceptor([
{ name: 'avatar', maxCount: 1 },
{ name: 'background', maxCount: 1 },
]))
Is there a way to do this with @aginix/nestjs-gcloud-storage
?
Hi, @n3n, I have reported a vulnerability issue in package @google-cloud/storage.
As far as I am aware, vulnerability CVE-2020-26289 detected in package date-and-time<0.14.2) is directly referenced by @google-cloud/[email protected], on which your package @aginix/[email protected] directly depends. As such, this vulnerability can also affect @aginix/[email protected] via the following path:
@aginix/[email protected] ➔ @google-cloud/[email protected] ➔ [email protected](vulnerable version)
Since @google-cloud/storage has released a new patched version @google-cloud/[email protected] to resolve this issue (@google-cloud/[email protected] ➔ [email protected](fix version)), then this vulnerability patch can be automatically propagated into your project only if you update your lockfile. The following is your new dependency path :
@aginix/[email protected] ➔ @google-cloud/[email protected] ➔ [email protected](vulnerability fix version)
.
A warm tip.
Best regards,
^_^
@post('upload')
@UseInterceptors(
GCloudStorageFileInterceptor('file', {
fileFilter: ['jpg', 'png'],
limits: { fileSize: 7 * 1024 * 1024 },
}),
)
uploadFile(@uploadedfile() file) {
console.log(file);
}
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:
nestjs-gcloud-storage/lib/gcloud-stroage-file.interceptor.ts
Lines 26 to 34 in 42fe011
const file = request[fieldName];
is incorrect, as according to multer docs:
body
object and a file
or files
object to the request
objectBut 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.
The feature should not be too hard to implement, and it's a key functionality that's missing rn.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.