Giter Site home page Giter Site logo

usb-files-manager's Introduction

title description
USB Files Manager
Read/write files on the USB device via SAF.

cordova-plugin-usbfilesmanager

This plugin implements a File API allowing read/write access to files residing on the USB device via SAF.

This plugin defines global cordova.plugins.USBFilesManager object.

Although in the global scope, it is not available until after the this.platform.ready() event.

this.platform.ready().then(() => {
    if (cordova.plugins['USBFilesManager']) {
        cordova.plugins['USBFilesManager'].saveFileToUSB(FILE_NAME, res => {}, err => {});
        cordova.plugins['USBFilesManager'].getFilesFromUSB(res => {}, err => {});
        cordova.plugins['USBFilesManager'].getFilesFromUSBByUri(URI, res => {}, err => {});
        cordova.plugins['USBFilesManager'].copyFileFromUSB(URI, FILE_NAME, res => {}, err => {});
    }
});

Installation

ionic cordova plugin add https://github.com/yokodima/USBFilesManager.git

Supported Platforms

  • Android

Save file to Chosen Directory

Here is an example of a saving file to the USB storage.

    const FILE_NAME = 'example.zip';
    cordova.plugins['USBFilesManager'].saveFileToUSB(FILE_NAME, res => {}, err => {});

Returns:

    result.put("error", errorCopy);
    result.put("uri", uri);

Get directory files list

Here is an example of a getting list files from chosen directory.

    cordova.plugins['USBFilesManager'].getFilesFromUSB(res => {}, err => {});

Returns:

    resultFile.put("isFile", file.isFile());
    resultFile.put("name", file.getName());
    resultFile.put("url", file.getUri());
    resultFile.put("type", file.getType());
    result.put(file.getName(), resultFile);

Get directory files list by Uri

Here is an example of a getting list files from recently chosen directory uri.

    const URI = 'content://com.externalstorage....';
    cordova.plugins['USBFilesManager'].getFilesFromUSBByUri(URI, res => {}, err => {});

Returns:

    resultFile.put("isFile", file.isFile());
    resultFile.put("name", file.getName());
    resultFile.put("url", file.getUri());
    resultFile.put("type", file.getType());
    result.put(file.getName(), resultFile);

Copy file from Chosen Directory

Here is an example of a saving file to the USB storage.

    const URI = uri returned from the getFilesFromUSB method;
    cordova.plugins['USBFilesManager'].copyFileFromUSB(URI, FILE_NAME, res => {}, err => {});

Returns:

    result.put("error", error);
    result.put("fileName", fileName);
    result.put("fileUri", fileUri);
    result.put("url", targetPath);

usb-files-manager's People

Contributors

freed0mdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.