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