Pesquisar na Comunidade
Mostrando resultados para as tags ''app hibrido''.
Encontrado 1 registro
-
Opa, to precisando muito de uma ajuda: estou tentando fazer o upload de arquivos de um app hibrido (rodando android) para um servidor. O código abaixo é executado sem erro, mas o upload não acontece. Será que alguem tem ideia de onde pode estar o erro? var images = []; var $imagesDiv; document.addEventListener("deviceready", init, false); function init() { $("#addPicture").on("touchend", selPic); $imagesDiv = $("#images"); $("#uploadPictures").on("touchend", uploadPics); } function selPic() { navigator.camera.getPicture(function(f) { var newHtml = "<img src='"+f+"'>"; $imagesDiv.append(newHtml); images.push(f); if(images.length === 1) { $("#uploadPictures").removeAttr("disabled"); } }, function(e) { alert("Error, check console."); console.dir(e); }, { quality: 50, sourceType: Camera.PictureSourceType.PHOTOLIBRARY, destinationType: Camera.DestinationType.FILE_URI }); } function uploadPics() { alert("Ok, going to upload "+images.length+" images."); var defs = []; var fd = new FormData(); images.forEach(function(i) { alert('processing '+i); var def = $.Deferred(); window.resolveLocalFileSystemURL(i, function(fileEntry) { alert('got a file entry'); fileEntry.file(function(file) { alert('now i have a file ob'); console.dir(file); var reader = new FileReader(); reader.onloadend = function(e) { var imgBlob = new Blob([this.result], { type:file.type}); fd.append('file'+(images.indexOf(i)+1), imgBlob); fd.append('fileName'+(images.indexOf(i)+1), file.name); def.resolve(); }; reader.readAsArrayBuffer(file); }, function(e) { alert('error getting file', e); }); }, function(e) { alert('Error resolving fs url', e); }); defs.push(def.promise()); }); $.when.apply($, defs).then(function() { alert("all things done"); var request = new XMLHttpRequest(); request.open('POST', 'url', true); request.send(fd); }); } Do lado do servidor, onde eu deveria receber a requisição e upar os arquivos, está conforme código abaixo: <?php header("Access-Control-Allow-Origin: *"); $imgFileName=date("Y").date("m").date("j")."_".$_POST['index']."_".rand(1000,9999).".jpg"; if(move_uploaded_file($_FILES['file']['tmp_name'], "anuncios/".$imgFileName)){ echo "upload ok"; //or anything you need } ?>