You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by Mikejo5000 <gi...@git.apache.org> on 2016/05/03 20:30:39 UTC

[GitHub] cordova-plugin-file-transfer pull request: added link to sample

GitHub user Mikejo5000 opened a pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145

    added link to sample

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/Mikejo5000/cordova-plugin-file-transfer master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #145
    
----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by daserge <gi...@git.apache.org>.
Github user daserge commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-221322800
  
    LGTM, minor comments


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-221028953
  
    @daserge Can you please review and help merge?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-217924472
  
    Sounds like there is a conflict with master - @Mikejo5001 Could you please rebase? Your diff should only contain the line you added.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-221342831
  
    @daserge Thanks for your review - can you make the improvements you suggest and help merge this in.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by cordova-qa <gi...@git.apache.org>.
Github user cordova-qa commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-219924763
  
    Cordova CI Build has completed successfully. 
    
    **Commit**     - [Link](https://github.com/apache/cordova-plugin-file-transfer/pull/145/commits/fd8ced3c22264687c40fd6c839cbe9338008ae63)
    **Dashboard** - [Link](http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1/)
    
    | Builder Name  | Console Output | Test Report | Device Logs  |
    |     :---:     |     :---:      |   :---:     |     :---:    |
    | [Windows 8.1 Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-store/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-store/console) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-store/testReport/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-store/artifact/) |
    | [Windows 10  Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-10-store/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-10-store/console) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-10-store/testReport/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-10-store/artifact/) |
    | [Windows 8.1 Phone]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-phone/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-phone/console) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-phone/testReport/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=windows-slave,platformName=windows-8.1-phone/artifact/) |
    | [iOS]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=ios/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=ios/console) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=ios/testReport/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=ios/artifact/) |
    | [Android Mac]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=android/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=android/console) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=android/testReport/) | [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-file-transfer-pr/1//label=mac-slave,platformName=android/artifact/) |
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by daserge <gi...@git.apache.org>.
Github user daserge commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#discussion_r64423218
  
    --- Diff: README.md ---
    @@ -315,3 +319,253 @@ If you are upgrading to a new (1.0.0 or newer) version of File, and you have pre
         cdvfile://localhost/persistent/path/to/file
     
     which can be used in place of the absolute file path in both `download()` and `upload()` methods.
    +
    +## Sample: Download and Upload Files <a name="sample"></a>
    +
    +Use the File-Transfer plugin to upload and download files. In these examples, we demonstrate several tasks like:
    +
    +* [Downloading a binary file to the application cache](#binaryFile)
    +* [Uploading a file created in your application's root](#uploadFile)
    +* [Downloading the uploaded file](#downloadFile)
    +
    +## Download a Binary File to the application cache <a name="binaryFile"></a>
    +
    +Use the File plugin with the File-Transfer plugin to provide a target for the files that you download (the target must be a FileEntry object). Before you download the file, create a DirectoryEntry object by using `resolveLocalFileSystemURL` and calling `fs.root` in the success callback. Use the `getFile` method of DirectoryEntry to create the target file.
    +
    +```js
    +window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {
    +
    +    console.log('file system open: ' + fs.name);
    +
    +    // Make sure you add the domain name to the Content-Security-Policy <meta> element.
    +    var url = 'http://cordova.apache.org/static/img/cordova_bot.png';
    +    // Parameters passed to getFile create a new file or return the file if it already exists.
    +    fs.root.getFile('downloaded-image.png', { create: true, exclusive: false }, function (fileEntry) {
    +        download(fileEntry, url, true);
    +
    +    }, onErrorCreateFile);
    +
    +}, onErrorLoadFs);
    +```
    +
    +>*Note* For persistent storage, pass LocalFileSystem.PERSISTENT to requestFileSystem.
    +
    +When you have the FileEntry object, download the file using the `download` method of the FileTransfer object. The 3rd argument to the `download` function of FileTransfer is the success callback, which you can use to call the app's `readBinaryFile` function. In this code example, the `entry` variable is a new FileEntry object that receives the result of the download operation.
    +
    +```js
    +function download(fileEntry, uri, readBinaryData) {
    +
    +    var fileTransfer = new FileTransfer();
    +    var fileURL = fileEntry.toURL();
    +
    +    fileTransfer.download(
    +        uri,
    +        fileURL,
    +        function (entry) {
    +            console.log("Successful download...");
    +            console.log("download complete: " + entry.toURL());
    +            if (readBinaryData) {
    +              // Read the file...
    +              readBinaryFile(entry);
    +            }
    +            else {
    +              // Or just display it.
    +              displayImageByFileURL(entry);
    +            }
    +        },
    +        function (error) {
    +            console.log("download error source " + error.source);
    +            console.log("download error target " + error.target);
    +            console.log("upload error code" + error.code);
    +        },
    +        null, // or, pass false
    +        {
    +            //headers: {
    +            //    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
    +            //}
    +        }
    +    );
    +}
    +```
    +
    +If you just need to display the image, take the FileEntry to call its toURL() function.
    +
    +```js
    +function displayImageByFileURL(fileEntry) {
    +    var elem = document.getElementById('imageFile');
    +    elem.src = fileEntry.toURL();
    +}
    +```
    +
    +Depending on your app requirements, you may want to read the file. To support operations with binary files, FileReader supports two methods, `readAsBinaryString` and `readAsArrayBuffer`. In this example, use `readAsArrayBuffer` and pass the FileEntry object to the method. Once you read the file successfully, construct a Blob object using the result of the read.
    +
    +```js
    +function readBinaryFile(fileEntry) {
    +    fileEntry.file(function (file) {
    +        var reader = new FileReader();
    +
    +        reader.onloadend = function() {
    +
    +            console.log("Successful file read: " + this.result);
    +            // displayFileData(fileEntry.fullPath + ": " + this.result);
    +
    +            var blob = new Blob([new Uint8Array(this.result)], { type: "image/png" });
    +            displayImage(blob);
    +        };
    +
    +        reader.readAsArrayBuffer(file);
    +
    +    }, onErrorReadFile);
    +}
    +```
    +
    +Once you read the file successfully, you can create a DOM URL string using `createObjectURL`, and then display the image.
    +
    +```js
    +function displayImage(blob) {
    +
    +    // Note: Use window.URL.revokeObjectURL when finished with image.
    +    var objURL = window.URL.createObjectURL(blob);
    +
    +    // Displays image if result is a valid DOM string for an image.
    +    var elem = document.getElementById('imageFile');
    +    elem.src = objURL;
    +}
    +```
    +
    +As you saw previously, you can call FileEntry.toURL() instead to just display the downloaded image (skip the file read).
    +
    +## Upload a File <a name="uploadFile"></a>
    +
    +When you upload a File using the File-Transfer plugin, use the File plugin to provide files for upload (again, they must be FileEntry objects). Before you can upload anything, create a file for upload using the `getFile` method of DirectoryEntry. In this example, create the file in the application's cache (fs.root). Then call the app's writeFile function so you have some content to upload.
    +
    +```js
    +function onUploadFile() {
    +    window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {
    +
    +        console.log('file system open: ' + fs.name);
    +        var fileName = "uploadSource.txt";
    +        var dirEntry = fs.root;
    +        dirEntry.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) {
    +
    +            // Write something to the file before uploading it.
    +            writeFile(fileEntry);
    +
    +        }, onErrorCreateFile);
    +
    +    }, onErrorLoadFs);
    +}
    +```
    +
    +In this example, create some simple content, and then call the app's upload function.
    +
    +```js
    +function writeFile(fileEntry, dataObj) {
    +    // Create a FileWriter object for our FileEntry (log.txt).
    +    fileEntry.createWriter(function (fileWriter) {
    +
    +        fileWriter.onwriteend = function () {
    +            console.log("Successful file write...");
    +            upload(fileEntry);
    +        };
    +
    +        fileWriter.onerror = function (e) {
    +            console.log("Failed file write: " + e.toString());
    +        };
    +
    +        if (!dataObj) {
    +          dataObj = new Blob(['file data to upload'], { type: 'text/plain' });
    +        }
    +
    +        fileWriter.write(dataObj);
    +    });
    +}
    +```
    +
    +Forward the FileEntry object to the upload function. To perform the actual upload, use the upload function of the FileTransfer object.
    +
    +```js
    +function upload(fileEntry) {
    +    // !! Assumes variable fileURL contains a valid URL to a text file on the device,
    +    var fileURL = fileEntry.toURL();
    +
    +    var success = function (r) {
    +        console.log("Successful upload...");
    +        console.log("Code = " + r.responseCode);
    +        displayFileData(fileEntry.fullPath + " (content uploaded to server)");
    --- End diff --
    
    I would define `displayFileData` or just replace it with `console.log`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by nikhilkh <gi...@git.apache.org>.
Github user nikhilkh commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-217923056
  
    :shipit:


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by Mikejo5000 <gi...@git.apache.org>.
Github user Mikejo5000 closed the pull request at:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by daserge <gi...@git.apache.org>.
Github user daserge commented on the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#issuecomment-221373959
  
    Merged in https://github.com/apache/cordova-plugin-file-transfer/commit/82c5af9b5dd6accbd6b2d25174d3c1f4e576e5b3
    @Mikejo5000 could you please close the PR?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-file-transfer pull request: added link to sample

Posted by daserge <gi...@git.apache.org>.
Github user daserge commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/145#discussion_r64423473
  
    --- Diff: README.md ---
    @@ -315,3 +319,253 @@ If you are upgrading to a new (1.0.0 or newer) version of File, and you have pre
         cdvfile://localhost/persistent/path/to/file
     
     which can be used in place of the absolute file path in both `download()` and `upload()` methods.
    +
    +## Sample: Download and Upload Files <a name="sample"></a>
    +
    +Use the File-Transfer plugin to upload and download files. In these examples, we demonstrate several tasks like:
    +
    +* [Downloading a binary file to the application cache](#binaryFile)
    +* [Uploading a file created in your application's root](#uploadFile)
    +* [Downloading the uploaded file](#downloadFile)
    +
    +## Download a Binary File to the application cache <a name="binaryFile"></a>
    +
    +Use the File plugin with the File-Transfer plugin to provide a target for the files that you download (the target must be a FileEntry object). Before you download the file, create a DirectoryEntry object by using `resolveLocalFileSystemURL` and calling `fs.root` in the success callback. Use the `getFile` method of DirectoryEntry to create the target file.
    +
    +```js
    +window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {
    +
    +    console.log('file system open: ' + fs.name);
    +
    +    // Make sure you add the domain name to the Content-Security-Policy <meta> element.
    +    var url = 'http://cordova.apache.org/static/img/cordova_bot.png';
    +    // Parameters passed to getFile create a new file or return the file if it already exists.
    +    fs.root.getFile('downloaded-image.png', { create: true, exclusive: false }, function (fileEntry) {
    +        download(fileEntry, url, true);
    +
    +    }, onErrorCreateFile);
    +
    +}, onErrorLoadFs);
    +```
    +
    +>*Note* For persistent storage, pass LocalFileSystem.PERSISTENT to requestFileSystem.
    +
    +When you have the FileEntry object, download the file using the `download` method of the FileTransfer object. The 3rd argument to the `download` function of FileTransfer is the success callback, which you can use to call the app's `readBinaryFile` function. In this code example, the `entry` variable is a new FileEntry object that receives the result of the download operation.
    +
    +```js
    +function download(fileEntry, uri, readBinaryData) {
    +
    +    var fileTransfer = new FileTransfer();
    +    var fileURL = fileEntry.toURL();
    +
    +    fileTransfer.download(
    +        uri,
    +        fileURL,
    +        function (entry) {
    +            console.log("Successful download...");
    +            console.log("download complete: " + entry.toURL());
    +            if (readBinaryData) {
    +              // Read the file...
    +              readBinaryFile(entry);
    +            }
    +            else {
    +              // Or just display it.
    +              displayImageByFileURL(entry);
    +            }
    +        },
    +        function (error) {
    +            console.log("download error source " + error.source);
    +            console.log("download error target " + error.target);
    +            console.log("upload error code" + error.code);
    +        },
    +        null, // or, pass false
    +        {
    +            //headers: {
    +            //    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
    +            //}
    +        }
    +    );
    +}
    +```
    +
    +If you just need to display the image, take the FileEntry to call its toURL() function.
    +
    +```js
    +function displayImageByFileURL(fileEntry) {
    +    var elem = document.getElementById('imageFile');
    --- End diff --
    
    Does it make sense to name it like `imageElement` instead?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org