I have been trying to solve this issue for some hours already and I can´t wrap my mind about what I should really do guys:
Basically I have the following code where first I get some data (first urls
and then urls.location
), and then I´ll try to send this arrayphotos
array as an object through an API patch
request.
uploadPhoto(e){
let arrayphotos = [{}]
new Promise(function() {
for(let i= 0; i<e.target.files.length; i++){
ReactS3.uploadFile(e.target.files[i], s3configUpload)
.then((urls) => {
arrayphotos.push((urls.location))
})
.catch((err) => {alert(err)})
}
console.log(arrayphotos)
}).then(
axios.patch(`${apiGatewayDevStage}/add-pictures`, {
site: this.props.match.params.gallery_name + "_" + this.state.authenticatedUser,
photos: arrayphotos
}).then(() => {
console.log('DB-Galleries en Dynamo updated')
}).catch(err => console.log(err))
)
}
I think where the problem is that the function is sending three objects (three photos ulrs) instead of sending in one object the three urls. When I console log after the arrayphotos is completed, this is what it appears:
So basically I guess that because the array is completed with three objects, then the DB just gets an empty array (I guess because of an error, because it doesnt appear any error in the axios error handler tbh).
How can I make the for loop so the array has only ONE object and inside the urls?