0
I have a button where I select a file, I would like to upload that file to my server(Java + Vraptor
). I can already get the file and also save the name of the file in the database along with the collaborator’s data. Now all that remains is to send this file to the server. I am using that model.
I upload it that way:
$scope.uploadFiles = function(file) {
$scope.f = file;
}
var salvarImagem = function(file) {
if (file && !file.$error) {
file.upload = Upload.upload({
//Não sei o que colocar aqui!
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {
file: file
}
});
file.upload.then(function(response) {
$timeout(function() {
file.result = response.data;
console.log("REsposta: " + response.data);
});
}, function(response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
});
file.upload.progress(function(evt) {
file.progress = Math.min(100, parseInt(100.0 *
evt.loaded / evt.total));
});
}
}
Then I call the function salvarImagem
within my function that saves the Collaborator:
$scope.adicionarColaborador = function(colaborador) {
if (!editar) {
colaborador.arquivo = $scope.f.name;
console.log('colaborador: ' + colaborador.arquivo)
colaboradorAPI.saveColaborador(colaborador).success(function(data) {
salvarImagem($scope.f);
.../Código omitido
What’s the next step now? How to receive this image on my server and save it in a directory, or how to save this image to a direct directory?
I use this directive to upload multiple files simultaneously: https://github.com/danialfarid/ng-file-upload
– OnoSendai