I've implemented this solution to upload the 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 particularly dislike this solution, but there are good points in it. If an image fails, all fail (which is expected). But I'm having problems with heavier images. What is the best practice when uploading these images? I thought of uparing one at a time, always invoking the next in the current callback, 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?