How do I change filename of the file?
See original GitHub issueI’d like to change the file name to other that’s send as a property of the data object, here’s the json of the file:
{ fieldname: 'file',
originalname: 'db.pdf',
encoding: '7bit',
mimetype: 'application/pdf',
destination: './client/public/docs/transactions/',
filename: '8a3fe7cb7369d9cffa8e17b162ec3d6b',
path: 'client\\public\\docs\\transactions\\8a3fe7cb7369d9cffa8e17b162ec3d6b',
size: 9179145 }
Client side upload with ng-file-upload
:
Upload
.upload( {
url: '/api/v1/upload',
data: {
file: vm.pdf,
new_name: vm.new_pdf_name //This is the name I want for the file
}
} )
.then(
function ( response ) { ... }
);
I’m using diskStorage
but the request
of filename
property function doesn’t receive new_file_name
property…
var storage = multer.diskStorage(
{
destination: './uploads/',
filename: function ( req, file, cb ) {
//req.body is empty...
cb( null, file.originalname );
}
}
);
How could I send the new_file_name
through that req.body
?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Rename a file - Microsoft Support
Open File Explorer by going to My Computer, or by pressing Windows Key + E on your keyboard. Find the file you want...
Read more >Rename a file or folder
To rename a file or folder: · Right-click on the item and select Rename, or select the file and press F2 . ·...
Read more >How do I rename a file in Windows?
There are many ways to rename a file in Windows. The easiest way is by right-clicking on the file and selecting Rename. You...
Read more >Rename a file - Files by Google Help
Rename a file · On your Android device, open Files by Google Files by Google · On the bottom, tap Browse Browse ·...
Read more >6 Ways to Rename Files and Folders in Windows 10
To rename a file from the context menu, right-click a folder, and click “Rename” from the context menu that appears. With the name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes that is the expected behaviour, the
filename
function is called whenever a file is detected on the wire. It needs to run before the file is actually consumed since it determines where to save it.Your request from the client looks like this:
You need to send it as such:
If
req.body
is empty, it means that the client sent the file before sending thenew_file_name
field. There is nothing we can do about it inmulter
.This has come up a number of times before, e.g. #146 where the workaround is further outlined.