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
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
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
Hello Ibrahim,
Could you please clarify, do you want too upload it to the Appery.io db, or to some other db?
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
Ibrahim,
Could you please detail, have you seen this tutorial: http://devcenter.appery.io/tutorials/... ?
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
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>
//Camera Section
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {}
// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
console.log('captureSuccess');
uploadFile(mediaFiles[0]);
}
// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
console.log('msg');
}
// A button will call this function
//
function captureImage() {
// Launch device camera application,
// allowing user to capture only one image by {limit: 1}
navigator.device.capture.captureImage(captureSuccess, captureError, { limit: 1 });
}
// Upload files to server
function upload(mediaFile) {
path = mediaFile.fullPath;
name = mediaFile.name;
Code: Select all
var options = new FileUploadOptions();
options.fileKey="file"
options.fileName=mediaFile.name;
options.mimeType="image/jpeg"
var params = new Object();
params.fullpath = path;
params.name = name;
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload( path, "http://www.serverurl.com/image_upload",
function(result) {
//upload successful
alert("upload successful");
alert(result);
},
function(error) {
//upload unsuccessful, error occured while upload.
alert("upload unsuccessful");
alert(error);
},
options
);
}
function uploadFile(mediaFile) {
path = mediaFile.fullPath;
Code: Select all
// Appery('file_input').val(path);
//alert(path);
//alert(Appery('file_input').val(path));
name = mediaFile.name;
console.log(path);
console.log(name);
var serverUrl = 'https://api.appery.io/rest/1/db/files/' + name;
console.log(serverUrl);
Code: Select all
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("X-Appery-Database-Id", '
454546454645445'),
request.setRequestHeader("X-Appery-Session-Token","444-b122-46a2-8bab-DEDEDE"),
request.setRequestHeader("Content-Type", "image/jpeg");
Code: Select all
},
url: path,
data:mediaFile.data,
processData: false,
contentType: false,
success: function(data) {
console.log(data);
console.log("upload successful");
alert(data);
alert("upload successful");
// Apperyio('file_input')=path;
//value
// console.log(Appery('file_input'));
//console.log(Appery('file_input'));
//console.log(Appery('file_input').value(path));
localStorage.setItem('db_file_name', name);
uploadMultipleFilesHelperNew(uploadService2,Appery('file_input'));
// OPTIONAL, this is the file name under which the image was stored in database....
localStorage.setItem('db_file_path', path);
localStorage.setItem('db_file_name', name);
},
error: function(data) {
console.log("upload unsuccessful");
console.log(data);
alert("upload unsuccessful");
alert(data);
// do something in case of an error...
}
});
}
</script>
/code
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';
any update
Hi Ibrahim,
Could you please show us what have you implemented so far and what exactly is not working?