Hi, I asked this in slack and was advised to post here.
I’m trying to take a picture with the camera and post it to a server. I was trying to avoid Parse but have just recently started playing around with it.
I’ve tried two methods with no success. Both of these examples are written within the Camera.takePicture callback, file is the File object passed to the callback.
We are currently working on making this a lot better. It is possible to do this in the current version without making it a base64 image by using Uno. If you can’t wait for the new API, I can try to code an examplpe for you.
Thanks so much! This is great. It may be a few days before I get to test this out (right now Fuse development is just something I’m doing in my spare time) but I’ll definitely give this a shot and report back!
Hi Jozef, did that happen when you used the Uno code you quoted or FileReader? What platforms/os did you try?
It happend when using the Uno code. I tried it on iOS using the Xcode simulator. I’ve used debug log’s to see if the image get’s passed to the actual Uno code and that worked. But when sending the file to the PHP script it seems like it get’s lost somewhere. Here’s the output from my debug log.
Do you have any advise on how to see if this is actually an image and how to convert it into a image file?
My php script looks like this.
<?php
$post = file_get_contents('php://input');
$test = $post;
$file = 'image.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= print_r($test, true);
// Write the contents back to the file
file_put_contents($file, $current);
?>
If I simply change the extention to .jpeg (tried this in my script and in finder) the image doesnt open
Hi Aders and everyone, i did something pretty simple to upload images, this is the code:
function TakePhoto()
{
CameraRoll.getImage()
.then(function(image) {
ImageTools.getBase64FromImage(image).then(function(b64){
UploadImage(b64);
});
}, function(error) {
// Will be called if the user aborted the selection or if an error occurred.
});
}
function UploadImage(image)
{
var xhr = new XMLHttpRequest();
xhr.addEventListener("progress",function(e){ Progress(e); }, false);
xhr.onprogress = Progress; //i tried this one too
xhr.addEventListener("load",function(e){ Done(e); }, false);
xhr.addEventListener("error",function(e){ Error(e); }, false);
xhr.open("POST","MyHiddenWebServiceURL",true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
var parametros = {'imagen':image,'id': ElCliente.value.IDCliente};
xhr.send(JSON.stringify(parametros));
}
function Done(e)
{
if(e.target.status===200)
{
var r = JSON.parse(e.target.responseText);
var datos = JSON.parse(r.d);
ElCliente = datos;
console.log("Subio imagen");
console.log("Exito " + e.target.responseText);
}else
{
console.log("Estaus erroneo " + e.target.status);
var r = JSON.parse(e.target.responseText);
console.log("El error es " + e.target.responseText);
}
}
function Error(e)
{
console.log("Error al subir imagen");
}
function Progress(e)
{
console.log("hay progreso");
if(e.lengthComputable)
{
var pc = Math.round(e.loaded * 100 / e.Total);
console.log("Subiendo: " + pc + "%");
}else{
console.log("No computable");
}
}
But i can`t get the progress event to fire and i was wondering if your code does it or if there is some way to get the progress event to fire with this code.
The image Uplodas correctly, by the way.
Sorry for the mix between English and Spanish in the code