title | description |
---|---|
USB Files Manager |
Read/write files on the USB device via SAF. |
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 => {});
}
});
ionic cordova plugin add https://github.com/yokodima/USBFilesManager.git
- Android
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);
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);
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);
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);