nestjs / azure-storage

Azure Storage module for Nest framework (node.js) ☁️
https://nestjs.com
MIT License
87 stars 35 forks source link

Add custom filename on upload #8

Closed manekinekko closed 5 years ago

manekinekko commented 5 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When uploading a file to Storage, we use the original filename.

Expected behavior

When uploading a file to Storage, we can provide a custom filename.

What is the motivation / use case for changing the behavior?

Users might want to have a custom logic when it comes to filename, or an internal pattern naming convention...etc

Notes

We should easily change this line so it can accept an external filename https://github.com/nestjs/azure-storage/blob/master/lib/azure-storage.service.ts#L116

manekinekko commented 5 years ago

It turns out that we can already do this with the current implementation, here is how:


 @Post('azure/upload')
 @UseInterceptors(FileInterceptor('file'))
 async UploadedFilesUsingService(
   @UploadedFile()
   file: UploadedFileMetadata,
 ) {
   file = {
     ...file,
     originalname: 'foo-bar.txt',
   };
   const storageUrl = await this.azureStorage.upload(file, {
     containerName: 'nest-demo-container-service',
   });
   Logger.log(`Storage URL: ${storageUrl}`, 'AppController');
 }```

I will add this to the readme.
DimosthenisK commented 5 years ago

How do you specify the folder though? I tried uploading a file with the name "folder/filename.ext" and it created a file literally named "folder/filename.ext" instead of the folder "folder" and the filename.ext inside.

manekinekko commented 5 years ago

I am sorry. Folder creation is not supported yet. Would you mind creating a different issue or a feature request to track this?