I use https://github.com/nervgh/angular-file-upload for file uploads.
I have a form which, in addition to uploading a file, sends some other fields. For clarity, I send only one field in this example:
$scope.save_with_upload = function(user) {
    $scope.uploader.formData = [{
        name: user.name,
    }];
    $scope.uploader.uploadAll();
}
Let’s say the value of the name input is Test 1.
formData at all.name field to Test 2 and hit Save. It sends the file and formData, but the value of name it sends is Test 1.name field to Test 3 and hit Save. It sends the file and formData, but the value of name it sends is Test 2.So it seems to always send the data that was assigned to formData before the last call to uploadAll.
To clarify: If I do dir(user, $scope.uploader.formData) just before calling uploadAll, it shows correct up-to-date values in both.
I’ve been struggling with it for a few hours and just can’t seem to see what’s wrong. Any ideas?
Attaching form fields to the FileItem object — rather than to FileUpload — fixes it:
uploader.onBeforeUploadItem = function(item) {
    formData = [{
        name: user.name,
    }];
    Array.prototype.push.apply(item.formData, formData);
};
The reason is, actually the settings on FileItem are used. When a file is added to the queue, settings from FileUpload are copied to FileItem. So any changes to FileUpload options made after a file has been added to the queue will have no effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With