After uploading a file using Angular.js ng-file-upload
, I am attempting to rename the file. However, when I remove the properties
ngf-min-height="400" ngf-resize="{width: 400, height:400}"
, I encounter an issue. Below is my code:
<input type="file" data-size="lg" name="bannerimage" id="imagefile1" ng-model="file" ngf-pattern="image/*" accept="image/*" ngf-max-size="2MB" ngf-min-height="400" ngf-resize="{width: 400, height:400}" custom-on-change="uploadFile" ngf-select="onFileSelect($file);" >
The corresponding controller code is as follows:
$scope.onFileSelect = function($files) {
fileURL=$files;
$scope.imageData='';
}
var file=fileURL;
var today=(Math.random() * new Date().getTime()).toString(36).replace(/\./g, '');
var newpath=today+"_"+ file.name;
file.name=newpath;
In the above code, I am appending a random number to the file name and replacing it successfully. However, if I remove
ngf-min-height="400" ngf-resize="{width: 400, height:400}"
from the file input like so:
<input type="file" data-size="lg" name="bannerimage" id="imagefile1" ng-model="file" ngf-pattern="image/*" accept="image/*" ngf-max-size="2MB" custom-on-change="uploadFile" ngf-select="onFileSelect($file);" >
In this scenario, I am unable to replace the file name and do not require restrictions on the file's height and width
.