Cordoba Adds Multiple File Transfer Images

I am working on cordova and jquery mobile project.

I was able to upload a single image with a file transfer plugin. Now I am trying to upload 2 or 3 images.

here is the html code:

<label for="image">Pictures:</label>
<a href="" id="image1Button" class="ui-btn" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">Get first picture</a><br>
<a href="" id="image2Button" class="ui-btn" onclick="getPhoto(pictureSource.PHOTOLIBRARY);" style="display:none;">Get second picture</a><br>
<a href="" id="image3Button" class="ui-btn" onclick="getPhoto(pictureSource.PHOTOLIBRARY);" style="display:none;">Get third picture</a><br>
<img id="image1" style="display:none;width:25%;">
<img id="image2" style="display:none;width:25%;">
<img id="image3" style="display:none;width:25%;">
<label for="title">Title</label>
<input data-clear-btn="true" name="title" id="title" value="" type="text">
<input value="Continue" type="submit" id="adButton">

here is the jquery code:

multi_upload(user_id);

function multi_upload(user_id) {

    var image1 = "image1";
    var image2 = "image2";
    var image3 = "image3";
    if($('#image2').prop('src') == ''){
        // upload one file
        upload(user_id, image1, "true");
    }
    if($('#image3').prop('src') == ''){
        // upload two files
        upload(user_id, image1, "false");
        upload(user_id, image2, "true");
    }
    if($('#image3').prop('src') != ''){
        // upload three files
        upload(user_id, image1, "false");
        upload(user_id, image2, "false");
        upload(user_id, image3, "true");
    }
}

function upload(user_id, imagesrc, final) {
    var img = '';
    var imageURI = '';
    img = document.getElementById(imagesrc);
    imageURI = img.src;
    console.log("[imageURI] "+imageURI);
    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
    options.mimeType = "image/jpeg";
    var params = {};
    params.timestamp = Math.round(+new Date()/1000);
    params.public_token = localStorage.getItem("token_public");
    params.hash = SHA1(params.timestamp+localStorage.getItem("token_private"));
    params.user_id = user_id;
    options.params = params;
    options.chunkedMode = false;
    var ft = new FileTransfer();
    if(final == "true"){
        ft.upload(imageURI, "http://www.example.com/api/index.php/privates/upload", finalwin, fail, options);
    }else{
        ft.upload(imageURI, "http://www.example.com/api/index.php/privates/upload", win, fail, options);
    }
}

If I upload two files, for example, the code will download twice compared to the last image selected. the console will give me an imageURI that looks like this:

file:///storage/sdcard0/Android/data/fr.myproject.propro/cache/modified.jpg?1418726649440:500

I assume this is a temporary file, so I assume that when I select the last file, it deletes the previous one ... how can I find the real path to these images?

+4
source share
1 answer

, (project/cache/modified.jpg) ( ) , FileTransfer.upload, , ( - -) , , .

, , modified.jpg?1418726649440 1418726649440modified.jpg, :

function renameFile(src, callback) {
    var d = new Date();
    //find the FileEntry for the file on the device
    window.resolveLocalFileSystemURL(src, function(fileEntry) {
        //get the parent directory (callback gives a DirectoryEntry)
        fileEntry.getParent(function(parent) {
            //rename the file, prepending a timestamp.
            fileEntry.moveTo(parent, d.getTime() + fileEntry.name, function(s) {
                //Callback with the new URL of the file.
                callback(s.nativeURL);
            }, function(error) {
                alert('Error on moving file!');
                callback(src); //Fallback, use the src given
            });
        }, function(error) {
            alert('Error on getting parent!');
            callback(src); //Fallback
        });
    }, function(error) {
        alert('Error on resolveLocalFileSystemURI!');
        callback(src); //Fallback
    });
}

src imageURI (.. ) callback , . ( , , getParent, , , DirectoryEntry src, , )

. File, , , , ( API ).

+2

All Articles