1

I m stuck in a situation and don't know how to do. i have a form along with file field what i want is when user click on final submit it should first upload image and then after get image filename and send another http request which submit other input fields along with image into database below show my code first

submit(){
 var formData = new FormData();
 var filesnew=[];
 formData.append( 'image', fileInput.files[0] );
 this.$http.post('/api/containers/pics/upload', formData)
   .then(function (response) {        
       filesnew=filesnew.push({"a":response.data.result.files.image[0].name})
            console.log('filesnew')
            })
 .catch(function (error) {
              console.log("error.response");

            });     
      }
console.log(filesnew["0"])
// another http request along with other detail and file name

when i click submit first i upload file then i want to pass file name to another ajax method to save data in database but i m getting undefine if i use "0" or 0 but i getting value in console if i use something like this console.log(filesnew) can anybody tell me what i m missing

here is console.log(filesnew)

  []
   0:"untitle.jpg",
   length:1,

i tried with console.log(filesnew["0"]) and console.log(filesnew['0']) but none of them working console.log(filesnew.length)--> getting value is 1 but above console not working i.e i m getting undefined

  • @SLaks can I know why you marked this duplicate. the link which you gave me above asyn and promise and I know this thing. but my question is that how I can achieve in single submit. check my starting point –  Jul 02 '18 at 05:23
  • You need to put all of your code in the promise chain. – SLaks Jul 02 '18 at 14:39
  • @SLaks I know promise chain but I want some other method like async, callback, push method how to use that in above code and the last thing is this question is still duplicate –  Jul 03 '18 at 05:51

0 Answers0