You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/02/07 17:06:40 UTC

spec commit: Add an manual test for FileTransfer

Updated Branches:
  refs/heads/master 4af4992de -> 9872f7204


Add an manual test for FileTransfer


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/9872f720
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/9872f720
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/9872f720

Branch: refs/heads/master
Commit: 9872f7204175f595bb813bb121f6b1302775b7b2
Parents: 4af4992
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Feb 7 11:06:20 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Feb 7 11:06:20 2013 -0500

----------------------------------------------------------------------
 camera/index.html |   61 +++++++++++++++++++++++++++++------------------
 1 files changed, 38 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/9872f720/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index 7a6a5f3..a18878a 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -46,41 +46,55 @@
         img.onloadend = callback;
     }
 
+    function getPictureFail(e) {
+        console.log("Error getting picture: " + e);
+        document.getElementById('camera_status').innerHTML = "Error getting picture.";
+    }
+
+    function getPictureWin(data) {
+        showPicture(data);
+        document.getElementById('camera_status').innerHTML = "Success";
+    }
+
     /**
      * Capture picture
      */
     function getPicture() {
-
-        //navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
-        //    destinationType: Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.CAMERA });
-
-        navigator.camera.getPicture(
-            function(data) {
-                //img.src = "data:image/jpeg;base64," + data;
-                showPicture(data);
-                document.getElementById('camera_status').innerHTML = "Success";
-            },
-            function(e) {
-                console.log("Error getting picture: " + e);
-                document.getElementById('camera_status').innerHTML = "Error getting picture.";
-            },
+        navigator.camera.getPicture(getPictureWin, getPictureFail, getPictureFail,
             { quality: 50, destinationType:
             Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.CAMERA});
-    };
+    }
+
+    function uploadImage(srcUrl) {
+        var ft = new FileTransfer(),
+            uploadcomplete=0,
+            progress = 0,
+            options = new FileUploadOptions();
+        options.fileKey="photo";
+        options.fileName='test.jpg';
+        options.mimeType="image/jpeg";
+        ft.onprogress = function(progressEvent) {
+          console.log('progress: ' + progressEvent.loaded + ' of ' + progressEvent.total);
+        };
+        var server = "http://cordova-filetransfer.jitsu.com";
+
+        ft.upload(srcUrl, server + '/upload', uploadedProfilePicture, function(message) { console.log("error: " + JSON.stringify(message)); }, options);
+        function uploadedProfilePicture(information_back){
+          console.log('win!');
+        }
+    }
 
     /**
      * Select image from library using a FILE_URI destination type
      */
-    function getImageUsingFileUri() {
+    function getImageUsingFileUri(upload) {
         navigator.camera.getPicture(
             function(data) {
-                showPicture(data);
-                document.getElementById('camera_status').innerHTML = "Success";
-            },
-            function(e) {
-                console.log("Error getting picture: " + e);
-                document.getElementById('camera_status').innerHTML = "Error getting picture.";
-            },
+                getPictureWin(data);
+                if (upload) {
+                    uploadImage(data);
+                }
+            }, getPictureFail,
             { quality: 50, destinationType:
             Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
     };
@@ -180,6 +194,7 @@
     <div class="btn large" onclick="getPicture();">Take Picture</div>
     <div class="btn large" onclick="getImageUsingFileUri();">Select Image Using File URI</div>
     <div class="btn large" onclick="getImageInfoUsingNativeUri();">Select Image Using Native URI</div>
+    <div class="btn large" onclick="getImageUsingFileUri(true);">Upload to jitsu with file URI</div>
     <h3>input type=file</h3>
     <input type="file" onchange="testNativeFile(this)">
     <h3>capture=camera</h3>