Hi all, I found phonegap yesterday, they have some examples on their site that show how to take a picture and another how to upload but I am having a hard combining the two examples. My goal it to be able to load my app, press a button, take a picture, the picture be displayed (and if acceptable) add a short title or description to the image then upload to the server.
here is the camera documentation (2.3.0): http://docs.phonegap.com/en/2.3.0/co...md.html#Camera
and here is the script i used to upload:
I really hope somebody can help me get on the right track here!Code:<html> <head> <title>File Transfer Example</title> <script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script> <script type="text/javascript" charset="utf-8"> var pictureSource; // picture source var destinationType; // sets the format of returned value // Wait for Cordova to load // document.addEventListener("deviceready", onDeviceReady, false); // Cordova is ready // function onDeviceReady() { // Retrieve image file location from specified source } function browse(){ navigator.camera.getPicture(uploadPhoto, function(message) { alert('get picture failed'); }, { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY } ); } function uploadPhoto(imageURI) { var options = new FileUploadOptions(); options.fileKey="file"; options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1); options.mimeType="image/jpeg"; var params = {}; params.value1 = "test"; params.value2 = "param"; options.params = params; var ft = new FileTransfer(); ft.upload(imageURI, encodeURI("http://www.example.com/upload.php"), win, fail, options); } function win(r) { console.log("Code = " + r.responseCode); console.log("Response = " + r.response); console.log("Sent = " + r.bytesSent); } function onFileSystemSuccess(fileSystem) { console.log(fileSystem.name); } function onResolveSuccess(fileEntry) { console.log(fileEntry.name); } function fail(evt) { console.log(evt.target.error.code); } function fail(error) { alert("An error has occurred: Code = " + error.code); console.log("upload error source " + error.source); console.log("upload error target " + error.target); } </script> </head> <body> <button onclick="browse();">upload photo</button> <br> <h1>Example</h1> <p>Upload File</p> </body> </html>


Reply With Quote
Bookmarks