Closed manekinekko closed 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.
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.
I am sorry. Folder creation is not supported yet. Would you mind creating a different issue or a feature request to track this?
I'm submitting a...
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