nervgh / angular-file-upload

[ALMOST NOT MAINTAINED] Angular File Upload is a module for the AngularJS framework
MIT License
3.44k stars 1.13k forks source link

Rename file according to input name #873

Closed Beiusxzw closed 3 years ago

Beiusxzw commented 3 years ago

In my html:

<a href="javascript:;" class="file_a">
     <input type="file" name="file1" nv-file-select uploader="uploader"  />
</a>

and my uploader:

   uploader.onAfterAddingFile = function(fileItem, e) {
        var fileName = fileItem.file.name.split('.');
        if (fileName.length < 2) {
            alert("Uploaded file must have a valid extension! For more information see the Supported Formats")
        }
        var fileExtension = "." + fileName.pop();
        fileItem.file.name = e + fileExtension;
        console.info('onAfterAddingFile', fileItem);
    }

I wonder if I can retrieve the name of the input and rename the uploaded file? Thanks!

ygj6 commented 3 years ago

Your method can modify the file name. Does this example meet your requirements: https://github.com/nervgh/angular-file-upload/pull/875/commits/c7891da3bafc5e1890b564fd245588538766efcd The final server receives the modified name: aaaa

Beiusxzw commented 3 years ago

problem solved. Thanks!