I am using ostrio:files to upload images in my meteor app. I am facing one problem that I am not able to set the custom name of my image is there anyway?
Hello @asadjs ,
- Use
namingFunction
to set file’s name used by a file system - Use
fileName
to set file’s name when it’s being downloaded
The code depends on what you want the file to be named on disk and / or on access
’ if (imagefile) {
//var file = e.currentTarget.files[0];
let self = this;
let fileName, fileExtension;
fileName = imagefile.name;
fileExtension = fileName.substr((fileName.lastIndexOf(’.’) + 1));
console.log (fileExtension);
let newFileName = res+’.’+fileExtension
console.log(newFileName);
if (imagefile) {
let uploadInstance = Images.insert({
file: imagefile,
// namingFunction:function(){return newFileName},
meta: {
locator: self.props.fileLocator,
userId: res // Optional, used to check on server for file tampering
},
streams: ‘dynamic’,
chunkSize: ‘dynamic’,
allowWebWorkers: true
}, false)
’
How do i use naming function here can you tell me please?
Since you’re looking at the insert here, you should try number 2 on dr.dimitru’s list.
In your insert method call, just add another attribute named fileName
with the name you want the file to have:
let uploadInstance = Images.insert({
file: imagefile,
fileName: newFileName,
meta: {
locator: self.props.fileLocator,
userId: res // Optional, used to check on server for file tampering
},
streams: 'dynamic',
chunkSize: 'dynamic',
allowWebWorkers: true
}, false)
Dear its not working i tried firstly that one it rename it with the collection id
What is the variable res
, you define newFileName
using it but it isn’t in your code snippet?
dear res is the id i am getting back from meteor function. By using that _id want to name the file