5
I implemented this solution to upload images:
MaquinaResource.save($scope.maquina, function (data, responseHeaders) {
var formDataImage = new FormData();
for(var i = 0 ; i < $scope.images.length; i++) {
formDataImage.append('file', $scope.images[i].file);
}
if($scope.images.length > 0) {
$http.post('rest/maquina/'+data.id+'/upload/imagem', formDataImage, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
}
}
I didn’t particularly like this solution, but there are positive points in it. If an image fails, they all fail (which is expected). But I am having problems with heavier images. What is the best practice when uploading these images? I thought of raising once at a time, always invoking the next one in the callback of the current one, but this would bring me a transactional problem (if an image fails the previous ones will already be saved). What is the best solution in these cases?