danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.59k forks source link

doing another Upload.upload() after the response of the first. #1907

Open SalvadorRomo opened 7 years ago

SalvadorRomo commented 7 years ago

I'm having some issue with figuring out how can i nest a Upload.upload function inside the response for the outer function.

 $scope.send = function(files) {
            var idpas;
            var var1 = {};
            Upload.upload({
                url: '/promotion/createPromotion',
                data: { file: files.file1, name: files.name, description: files.description, startDate: files.start_date, endDate: files.end_date }

            }).then(function(resp) {

                    Upload.upload({
                        url: '/promotion/createImage',
                        data: { files: files.file2, id: resp.data[0].id }
                    }).then(function(resp) {
                        console.log(resp.status);
                    }, function(resp) {

                    }, function(evt) {
                        var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                        console.log('progress: ' + progressPercentage + '% ');

                    });

                //$scope.send2(files, resp.data[0].id);
            }, function(resp) {
                console.log('Error status: ' + resp.status);
            }, function(evt) {

                var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
            });

        };

an this is my html.


 <div class="field" style="border: none;">
                    <label>file</label>
                    <input id="various" type="file" ngf-select ng-model="CreatePromotion.file1"  name="file" >
                  </div>
                     <div class="field" style="border: none;">
                    <label>image</label>
                    <input id="various2" type="file" ngf-select ng-model="CreatePromotion.file2"  name="files" >
                  </div>

All i want to do is to upload the image after the the files and data has been already inserted and as result; take the response to get the id of the created record and update it with an image whose input is File2 in the html.
But always is giving an exception telling that the id for the response of the first request , doesn't exist and should exist since the second request is inside the response of the first. I'v done everything and only got it work with small size files