Is there any way to change choosen file name? For example, I choose a file name img1. On choosing the file it have to change to dynamicname. Is there any way to change name?
<input type="file" fd-input/>
Is there any way to change choosen file name? For example, I choose a file name img1. On choosing the file it have to change to dynamicname. Is there any way to change name?
<input type="file" fd-input/>
Here is a way to change a filename inside a directive:
app.directive('file', function() {
return {
scope: {
file: '='
},
link: function(scope, el, attrs) {
el.bind('change', function(event) {
var files = event.target.files;
var file = files[0];
scope.file = 'New file name';
scope.$apply();
});
}
};
});
Use it as following:
<input type="file" file="param.file" />
If you have access to FormData you can use append method to change file name.
Refer this doc for more information.
var files = $("#fileUpload").get(0).files;
if (files.length > 0) {
var data = new FormData();
var ext = files[0].name.match(/\.(.+)$/)[1];
var fileName = Math.random().toString(36).substr(2, 19) + "." + ext;
// Add the uploaded image content to the form data collection
if (files.length > 0) {
//data.append("UploadedImage", files[0]); //if you want to pass default name
data.append("UploadedImage", files[0],fileName);
}
HTML code -
<input id="fileUpload" type="file" ng-file-accept="'.jpg , .jpeg ,.bmp , .gif ,.png'" accept="image/*" />