Yahia Ammar
Yahia Ammar

Reputation: 280

unable to send a base 64 image to server with angular js

i would like to send a base 64 image to the server side using the $http.get

$http.get(myurl+'?image='+image)

the image variable looks like:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOYAAAJYCAYAAADG7OkVAAAgAElEQVR4Xuy9CXhV1bn//w0Jmc/JAA51......

but i have a http error when executing the url: 400 (Bad request)

i think that the problem is due to the image variable length = 114498

how can i send a base 64 image using angular ?

Upvotes: 1

Views: 1691

Answers (1)

Ranjith S
Ranjith S

Reputation: 205

You have to use http post and suppose if you are using multi form data then you have to use

        var fd = new FormData();
    fd.append('file', file);
    $http.post(url, fd, {
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined}
    })
    .success(function(){
        //success
    })
    .error(function(){
        //failed
    });

where file is the actual file you are sending to server

Upvotes: 2

Related Questions