Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

I'm trying to send an image from an ionic app to an external API via server code, using the camera_getPicture plugin, but the image data is blank.

This is the mapping from the plugin to the var:

Image

This is the code I am using, but the $scope.im is null?

pre
var requestData = {};
/CLICK TO EDIT MAPPING/

// read more about using rest services: https://links.appery.io/ve-snippet-rest
Apperyio.get("Camera_getPicture")(requestData).then(
function(success){ // success callback
(function mapping8582(success, $scope){
var im_scope = $scope.im;
im_scope = success.image;
$scope.im = im_scope;
/CLICK TO EDIT MAPPING/

Code: Select all

     $.ajax({ 
         type: "POST", 
         url: 'https://dashboard.cmg-org.com/jobs/add_image_post', 
         data: "image="+ $scope.im, 
         success: function(data){ 

         } 
     }); 

 })(success, $scope); 

},
function(error){ // callback to handle request error

},
function(notify){ // notify callback, can fire few times

});
/pre

I'm receiving the request on the server fine, but the image data is empty.

What am i doing wrong?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

Hello,

Could you check what value you send to that API? Please check it on the Network tab of Weinre.

Also, please be sure that variable is defined

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

OK, so the var is populated. But i think the issue is that the data is Base64, so its too big to send via get. I tried sending a static variable with preset text, and this was received on the server, but when changed back to the scope var, it was empty.

Can I send POST via a service?

This is my service, I have it set to POST, but the variables are being set via GET??

Image

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

You are right, it is not possible to send base64 images as a parameter of the request. Please use the method "POST" here and send that value in the body of the request

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

OK, but how do i get the variable image, into the body of the request?

On the service request, you can add header variables and parameter variables, but how do you add body request variables?

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

And how would you map them to the request?

1.So from the page, like this?

requestData.body.image = thedata;

  1. How do i send this in the service. Like this?

    "body": {
    "image": request.get('image'),
    }

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

  • Please set the Request Content Type = JSON for that service
    Image
    • Add the parameter e.g. "image" to the body of the service Image
    • use the simple mapping to that parameter from your base64 value:
      Image
Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

Ok thanks for that.

Just one more thing, how do I assign the variable to the body of the server code? Like this?

"body": {
"image": request.get('image'),
}

Because it is empty. If i replace request.get('image') with any text for example '1234', it is received on my server.

But request.get('image') is empty.

I know the data is being set via:

_.set(requestData.data, 'image', im_scope);

I can view the data in the variable and it is set.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

Please use this Server Code to read the body parameter "image":
prevar body = request.object();
var image = body.image;/pre

More information you can find here: https://docs.appery.io/reference#serv...

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

How to send a picture from Ionic camera_getPicture plugin to an external API service

Ok thanks. I can now receive the base64 on the server. But now because I have changed the service request content type to JSON, my authorisation header is missing?

Any idea why this is now being removed?

Return to “Issues”