Ibrahim Ahmed Taymor
Posts: 0
Joined: Mon Jan 20, 2014 9:27 pm

how to upload image capture from camera via POST ?

how to upload image capture from camera via POST ?
to call api
http://www.faceplusplus.com/recogniti...
the binary data of the image uploaded via POST

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

how to upload image capture from camera via POST ?

Hello Ibrahim,

Could you please clarify, do you want too upload it to the Appery.io db, or to some other db?

Ibrahim Ahmed Taymor
Posts: 0
Joined: Mon Jan 20, 2014 9:27 pm

how to upload image capture from camera via POST ?

thank you for fast response.
i need to upload to Appery.io db as Files to get imge URL sent to http://www.faceplusplus.com/recogniti...

like

https://api.appery.io/rest/1/db/files...

or

sent to http://www.faceplusplus.com/recogniti... direct using the binary data of the image uploaded via POST

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

how to upload image capture from camera via POST ?

Ibrahim,

Could you please detail, have you seen this tutorial: http://devcenter.appery.io/tutorials/... ?

Ibrahim Ahmed Taymor
Posts: 0
Joined: Mon Jan 20, 2014 9:27 pm

how to upload image capture from camera via POST ?

yes
but in the tutorial the image is base64 ( i need URL to send to another API)

like this tutorial
http://devcenter.appery.io/tutorials/...

i can't send image is base64 to the server (i need url file)
like

https://api.appery.io/rest/1/db/files...

Ibrahim Ahmed Taymor
Posts: 0
Joined: Mon Jan 20, 2014 9:27 pm

how to upload image capture from camera via POST ?

i am try this code but the image not working have a text (file:/storage/emulated/0/DCIM/Camera/1418401211483.jpg)

any advice
i call

code

captureImage()
/code
code
<script>
&#47;&#47;Camera Section
&#47;&#47; Wait for PhoneGap to load
document&#46;addEventListener("deviceready", onDeviceReady, false);

&#47;&#47; PhoneGap is ready
function onDeviceReady() {}

&#47;&#47; Called when capture operation is finished
&#47;&#47;
function captureSuccess(mediaFiles) {
console&#46;log('captureSuccess');
uploadFile(mediaFiles[0]);
}

&#47;&#47; Called if something bad happens&#46;
&#47;&#47;
function captureError(error) {
var msg = 'An error occurred during capture: ' + error&#46;code;
navigator&#46;notification&#46;alert(msg, null, 'Uh oh!');
console&#46;log('msg');
}

&#47;&#47; A button will call this function
&#47;&#47;
function captureImage() {
&#47;&#47; Launch device camera application,
&#47;&#47; allowing user to capture only one image by {limit: 1}
navigator&#46;device&#46;capture&#46;captureImage(captureSuccess, captureError, { limit: 1 });
}

&#47;&#47; Upload files to server
function upload(mediaFile) {
path = mediaFile&#46;fullPath;
name = mediaFile&#46;name;

Code: Select all

 var options = new FileUploadOptions(); 
 options&#46;fileKey="file&quot 
 options&#46;fileName=mediaFile&#46;name; 
 options&#46;mimeType="image/jpeg&quot 

 var params = new Object(); 
 params&#46;fullpath = path; 
 params&#46;name = name; 

 options&#46;params = params; 
 options&#46;chunkedMode = false; 

 var ft = new FileTransfer(); 
 ft&#46;upload( path, "http:&#47;&#47;www&#46;serverurl&#46;com/image_upload", 
     function(result) { 
&#47;&#47;upload successful 

alert("upload successful");
alert(result);
},
function(error) {
&#47;&#47;upload unsuccessful, error occured while upload&#46;
alert("upload unsuccessful");
alert(error);
},
options
);
}

function uploadFile(mediaFile) {
path = mediaFile&#46;fullPath;

Code: Select all

 &#47;&#47;    Appery('file_input')&#46;val(path); 
 &#47;&#47;alert(path); 
 &#47;&#47;alert(Appery('file_input')&#46;val(path)); 

name = mediaFile&#46;name;
console&#46;log(path);
console&#46;log(name);
var serverUrl = 'https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/files/' + name;
console&#46;log(serverUrl);

Code: Select all

 $&#46;ajax({ 
     type: "POST", 
     beforeSend: function(request) { 
         request&#46;setRequestHeader("X-Appery-Database-Id", ' 

454546454645445'),
request&#46;setRequestHeader("X-Appery-Session-Token","444-b122-46a2-8bab-DEDEDE"),
request&#46;setRequestHeader("Content-Type", "image/jpeg");

Code: Select all

     }, 
     url: path, 
     data:mediaFile&#46;data, 
     processData: false, 
     contentType: false, 
     success: function(data) { 
     console&#46;log(data);  
          console&#46;log("upload successful"); 
         alert(data); 
         alert("upload successful");  
         &#47;&#47;  Apperyio('file_input')=path; 
         &#47;&#47;value 
         &#47;&#47;     console&#46;log(Appery('file_input'));  

         &#47;&#47;console&#46;log(Appery('file_input')); 
         &#47;&#47;console&#46;log(Appery('file_input')&#46;value(path));  
         localStorage&#46;setItem('db_file_name', name); 

         uploadMultipleFilesHelperNew(uploadService2,Appery('file_input')); 

         &#47;&#47; OPTIONAL, this is the file name under which the image was stored in database&#46;&#46;&#46;&#46; 
         localStorage&#46;setItem('db_file_path', path); 
         localStorage&#46;setItem('db_file_name', name); 

      }, 
     error: function(data) { 
          console&#46;log("upload unsuccessful"); 
          console&#46;log(data); 
         alert("upload unsuccessful"); 
         alert(data); 
         &#47;&#47; do something in case of an error&#46;&#46;&#46; 
     } 
 }); 

}
</script>
/code

Ihor Didevych
Posts: 0
Joined: Wed Nov 19, 2014 7:55 pm

how to upload image capture from camera via POST ?

Hi Ibrahim,

1) You should use this tutorial
http://devcenter.appery.io/tutorials/...
2) Next step, after your image uploaded, you should get URL to your image.
After you send image to DB, You'll get response file name.
So on success event add javascript handler you can easily generate url to your file like this: var url = 'https://api.appery.io/rest/1/db/files...'+ data.filename+'?encoded="base64"&masterKey=MASTER_KEY';

Ibrahim Ahmed Taymor
Posts: 0
Joined: Mon Jan 20, 2014 9:27 pm

how to upload image capture from camera via POST ?

kindly be informed that step one working but URL not working
may be the table is empty.

Image

Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

how to upload image capture from camera via POST ?

Hi Ibrahim,

Could you please show us what have you implemented so far and what exactly is not working?

Return to “Issues”