Send image via POST in English

Asked

Viewed 513 times

-1

HELP. I am trying to send an image to a web service via POST. no Postman tested and worked teste no postman

in my controller I did so

$scope.upload = function (files) {
        var fd = new FormData();
        fd.append('imagem', files[0]);
        midanaAPI.cadastrarImagem(fd).success(
                function (data) {
                    if (data.Status) {
                        $scope.foto = data.UrlImage;
                    }else {
                        $scope.mensagemErro = "Não foi possível carregar a Imagem, tente novamente.";
                    }
                });
    }

this midanaAPI.cadastrarImage(fd) is calling my service, follows the code

var _cadastrarImagem = function (imagem) {
    var data = 'Foto='+imagem;
    var config = {
        headers: {
            'Content-Type': undefined,
            'Device': "midayas.Device",
            'Token': "midayas.Token"
        }
    };
    return $http.post(configValor.baseUrl + "Upload/File", data, config);
};

only that Web Service does not find any file in the request.

1 answer

0


solved... It was just bullshit. instead of image the server was waiting Photo so the line fd.append('image', files[0]); was like this fd.append('Photo', files[0]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.