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/12 04:15:59 UTC

[8/11] spec commit: [CB-2213] Added a test for FileTransfer.upload.

[CB-2213] Added a test for FileTransfer.upload.


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/5569edc1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/5569edc1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/5569edc1

Branch: refs/heads/master
Commit: 5569edc17a5670afe9fd0cec8be32bf10abd81d8
Parents: a745736
Author: Max Woghiren <ma...@gmail.com>
Authored: Mon Jan 21 13:08:09 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Feb 11 21:20:35 2013 -0500

----------------------------------------------------------------------
 camera/index.html |  125 ++++++++++++++++++++++++++++--------------------
 1 files changed, 73 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/5569edc1/camera/index.html
----------------------------------------------------------------------
diff --git a/camera/index.html b/camera/index.html
index fd3c6d0..8a48860 100644
--- a/camera/index.html
+++ b/camera/index.html
@@ -49,7 +49,7 @@
         img.style.display = "block";
         img.src = url;
         img.onloadend = callback;
-    }
+    };
 
     function getPictureFail(e) {
         console.log("Error getting picture: " + e);
@@ -197,51 +197,6 @@
             Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
     };
 
-    function testNativeFile(inputEl) {
-        // iOS 6 likes to dead-lock in the onchange context if you
-        // do any alerts or try to remote-debug.
-        window.setTimeout(function() {
-            testNativeFile2(inputEl);
-        }, 0);
-    }
-
-    function testNativeFile2(inputEl) {
-        if (!inputEl.value) {
-            alert('No file selected.');
-            return;
-        }
-        var file = inputEl.files[0];
-        if (!file) {
-            alert('Got value but no file.');
-            return;
-        }
-        var URLApi = window.URL || window.webkitURL;
-        var statusText = '';
-        if (URLApi) {
-            var blobURL = URLApi.createObjectURL(file);
-            if (blobURL) {
-                showPicture(blobURL, function() {
-                    URLApi.revokeObjectURL(blobURL);
-                });
-            } else {
-                statusText = 'URL.createObjectURL returned null';
-            }
-        } else {
-            statusText = 'URL.createObjectURL() not supported.';
-        }
-        document.getElementById('camera_status').innerHTML = statusText;
-        var reader = new FileReader();
-        reader.onloadend = function() {
-            if (!reader.result) {
-                statusText += ' FileReader.readAsDataURL() failed';
-            } else {
-                statusText += ' DataURL size: ' + reader.result.length;
-            }
-            document.getElementById('camera_status').innerHTML = statusText;
-        };
-        reader.readAsDataURL(file);
-    }
-
     function copyImageUsingNativeUri() {
         var onFileMoved = function(fileEntry) {
             handleUnexpectedSuccess("FileEntry.moveTo");
@@ -325,6 +280,76 @@
             Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
     };
 
+    function uploadImageUsingNativeUri() {
+        var onFileUploaded = function(response) {
+            document.getElementById('camera_status').innerHTML += "FileTransfer.upload <b>success</b>: response = " + response.responseCode + ".<br />";
+        };
+
+        var onFileUploadError = function(error) {
+            document.getElementById('camera_status').innerHTML += "FileTransfer.upload <b>error</b> (code: " + error.code + ").<br />";
+        };
+
+        clearStatus();
+        navigator.camera.getPicture(
+            function(data) {
+                var options = new FileUploadOptions();
+                options.fileName = "image.png";
+                options.mimeType = "image/png";
+
+                var fileTransfer = new FileTransfer();
+                fileTransfer.upload(data, "http://cordova-filetransfer.jitsu.com/upload", onFileUploaded, onFileUploadError, options);
+            },
+            onGetPictureError,
+            { quality: 50, destinationType:
+            Camera.DestinationType.NATIVE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY});
+
+    };
+
+    function testNativeFile(inputEl) {
+        // iOS 6 likes to dead-lock in the onchange context if you
+        // do any alerts or try to remote-debug.
+        window.setTimeout(function() {
+            testNativeFile2(inputEl);
+        }, 0);
+    };
+
+    function testNativeFile2(inputEl) {
+        if (!inputEl.value) {
+            alert('No file selected.');
+            return;
+        }
+        var file = inputEl.files[0];
+        if (!file) {
+            alert('Got value but no file.');
+            return;
+        }
+        var URLApi = window.URL || window.webkitURL;
+        var statusText = '';
+        if (URLApi) {
+            var blobURL = URLApi.createObjectURL(file);
+            if (blobURL) {
+                showPicture(blobURL, function() {
+                    URLApi.revokeObjectURL(blobURL);
+                });
+            } else {
+                statusText = 'URL.createObjectURL returned null';
+            }
+        } else {
+            statusText = 'URL.createObjectURL() not supported.';
+        }
+        document.getElementById('camera_status').innerHTML = statusText;
+        var reader = new FileReader();
+        reader.onloadend = function() {
+            if (!reader.result) {
+                statusText += ' FileReader.readAsDataURL() failed';
+            } else {
+                statusText += ' DataURL size: ' + reader.result.length;
+            }
+            document.getElementById('camera_status').innerHTML = statusText;
+        };
+        reader.readAsDataURL(file);
+    };
+
     function handleUnexpectedError(methodName, errorCode) {
         document.getElementById('camera_status').innerHTML += "" + methodName + " <b>error</b> (code: " + errorCode + ").<br />";
     };
@@ -359,7 +384,7 @@
         		alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
         	}
         },1000);
-    }
+    };
 
 </script>
 
@@ -373,14 +398,10 @@
     </div>
     <h2>Action</h2>
     <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>
-    <div class="btn large" onclick="getImageInfoUsingNativeUri();">Native URI: Select Image, Show Info</div>
-    <div class="btn large" onclick="getImageUsingNativeUri();">Native URI: Select Image, Show Image</div>
     <div class="btn large" onclick="getImageUsingNativeUri();">Select Image Using Native URI</div>
     <div class="btn large" onclick="copyImageUsingNativeUri();">Copy Image Using Native URI</div>
     <div class="btn large" onclick="writeImageUsingNativeUri();">Write Image Using Native URI</div>
+    <div class="btn large" onclick="uploadImageUsingNativeUri();">Upload Image Using Native URI</div>
     <h3>input type=file</h3>
     <input type="file" onchange="testNativeFile(this)">
     <h3>capture=camera</h3>