Skip to main content

Phonegap file uploader in android


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>File Transfer Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
    <script type="text/javascript" charset="utf-8">

        // Wait for PhoneGap to load
        //
        // document.addEventListener("deviceready", onDeviceReady, false);
  function imageObject(){
        var options,
        fileEntry,
        ft,
        imageURI        
        };
       
        imageObject.prototype = {
        // 기본 셋팅
        initUpload : function(imageURI){
        console.log("initUpload");
        image.options = new FileUploadOptions();
        window.resolveLocalFileSystemURI(imageURI, image.onSuccessFile, image.onFailFile);
        image.imageURI = imageURI;
       
        image.options.fileKey="file";
            image.options.fileName=image.fileEntry.name;          
            image.options.mimeType="image/jpeg";
        image.ft = new FileTransfer();
        },
        // 파일전송
        send : function(){
        image.ft.upload(image.imageURI, "http://203.233.82.229/non/test/file.json", win, fail, image.options);
        },
        onSuccessFile : function(f){
        console.log("getFile");
        image.fileEntry = f;
        alert(f.name);
        },
        onFailFile : function(f){
       
        }
        }
        var image = new imageObject();
       

        // PhoneGap is ready
        //
        function readImageFile() {

            // Retrieve image file location from specified source
            navigator.camera.getPicture(image.initUpload,
                                        function(message) { alert('get picture failed'); },
                                        { quality: 50,
                                        destinationType: navigator.camera.DestinationType.FILE_URI,
                                        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
                                        mediaType: Camera.MediaType.ALLMEDIA }
                                        );

        };
       
        function win(r) {
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            console.log("Sent = " + r.bytesSent);
            alert("status : " + JSON.parse(r.response).status);
        }

        function fail(error) {
            alert("An error has occurred: Code = " = error.code);
        }    
     

        </script>
</head>
<body>
    <h1>Example</h1>
    <p>With PhoneGap API</p>
    <button onclick="readImageFile()">Open Image</button>
    <button onclick="image.send()">Send To Server</button>
    <br>
    <br>
    <p>With Original Form</p>
    <form method='POST' enctype='multipart/form-data' action='http://203.233.82.229/non/test/file.json'>
File to upload: <input type="file" name="file"><br>
Notes about the file: <input type="text" name="note"><br>
<br>
<input type="submit" value="Press"> to upload the file!
</form>
   
</body>
</html>

Comments

Popular posts from this blog

codefights smooth sailing ( CommonCharacterCount)

https://codefights.com/arcade/intro/level-3/JKKuHJknZNj4YGL32publicstaticintcommonCharacterCount(String s1, String s2) { int sum = 0; char[] as= s1.toCharArray(); char[] bs= s2.toCharArray(); int[] ias = newint[126]; int[] ibs = newint[126]; for (int i = 0; i < as.length; i++) { ias[(int)as[i]]++; } for (int i = 0; i < bs.length; i++) { ibs[(int)bs[i]]++; } for (int i = 0; i < ibs.length; i++) { sum += Math.min(ias[i], ibs[i]); } return sum; }

Given two strings, find the number of common characters between them. Example For s1 = "aabcc" and s2 = "adcaa", the output should be
commonCharacterCount(s1, s2) = 3. Strings have 3 common characters - 2 "a"s and 1 "c". Input/Output [time limit] 3000ms (java)[input] string s1 A string consisting of lowercase latin letters a-z. Guaranteed constraints:
1 ≤ s1.length ≤ 15. [input] string s2 A string consisting of lowercase latin letters a-z. Guaranteed constr…

Bucket Sort in python

I make buckets as many as size of arr
and put data.

arr = [0.897, 0.565, 0.656, 0.1234, 0.665, 0.3434] def bucketSort(arr, size): buckets = [[] for i in range(size)] # put arr in bucket for i in range(len(arr)): num = size*arr[i] buckets[int(num)].append(arr[i]) output = [] # use insertion sort for i in range(len(buckets)): insertionSort(buckets[i]) # concat all data for i in range(len(buckets)): while len(buckets[i]) > 0: output.append(buckets[i].pop(0)) return output def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp def insertionSort(arr): for i in range(1, len(arr)): index= i print("index : " + str(i)) while index!=0: if arr[index] < arr[index-1]: temp = arr[index] arr[index]= arr[index-1] arr[index-1] = temp index = index-1print(arr) else …