diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java index 90d12b0c2..d6e5ab253 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java @@ -282,7 +282,9 @@ private void saveFile(PluginCall call, File file, String data) { MediaScannerConnection.scanFile(getContext(), new String[] {file.getAbsolutePath()}, null, null); } Log.d(getLogTag(), "File '" + file.getAbsolutePath() + "' saved!"); - call.success(); + JSObject result = new JSObject(); + result.put("uri", Uri.fromFile(file).toString()); + call.success(result); } else { call.error("FILE_NOTCREATED"); } diff --git a/core/package-lock.json b/core/package-lock.json index 59c4f2801..d070792ad 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -1,6 +1,6 @@ { "name": "@capacitor/core", - "version": "1.4.0", + "version": "1.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 00070343f..7da5febcc 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -754,6 +754,7 @@ export interface FileReadResult { export interface FileDeleteResult { } export interface FileWriteResult { + uri: string; } export interface FileAppendResult { } diff --git a/core/src/web/filesystem.ts b/core/src/web/filesystem.ts index 0e2232cf0..72d9cd346 100644 --- a/core/src/web/filesystem.ts +++ b/core/src/web/filesystem.ts @@ -176,7 +176,9 @@ export class FilesystemPluginWeb extends WebPlugin implements FilesystemPlugin { content: !encoding && data.indexOf(',') >= 0 ? data.split(',')[1] : data, }; await this.dbRequest('put', [pathObj]); - return {}; + return { + uri: pathObj.path + }; } /** diff --git a/electron/src/electron/filesystem.ts b/electron/src/electron/filesystem.ts index 5cfff5e6d..014b8f748 100644 --- a/electron/src/electron/filesystem.ts +++ b/electron/src/electron/filesystem.ts @@ -71,7 +71,7 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu return; } - resolve(); + resolve({uri: lookupPath}); }); }); } diff --git a/example/src/pages/filesystem/filesystem.ts b/example/src/pages/filesystem/filesystem.ts index 71196f0b2..b7e256f10 100644 --- a/example/src/pages/filesystem/filesystem.ts +++ b/example/src/pages/filesystem/filesystem.ts @@ -27,18 +27,18 @@ export class FilesystemPage { console.log('ionViewDidLoad FilesystemPage'); } - fileWrite() { + async fileWrite() { try { - Plugins.Filesystem.writeFile({ + const result = await Plugins.Filesystem.writeFile({ path: 'secrets/text.txt', data: "This is a test", directory: FilesystemDirectory.Documents, encoding: FilesystemEncoding.UTF8 }); + console.log('Wrote file', result); } catch(e) { console.error('Unable to write file (press mkdir first, silly)', e); } - console.log('Wrote file'); } async fileRead() { @@ -131,12 +131,13 @@ export class FilesystemPage { async directoryTest() { try { - await Plugins.Filesystem.writeFile({ + const result = await Plugins.Filesystem.writeFile({ path: 'text.txt', data: "This is a test", directory: FilesystemDirectory.Data, encoding: FilesystemEncoding.UTF8 }); + console.log('wrote file', result); let stat = await Plugins.Filesystem.stat({ path: 'text.txt', directory: FilesystemDirectory.Data diff --git a/ios/Capacitor/Capacitor/Plugins/Filesystem.swift b/ios/Capacitor/Capacitor/Plugins/Filesystem.swift index 889c1e9ae..d8bc56a2d 100644 --- a/ios/Capacitor/Capacitor/Plugins/Filesystem.swift +++ b/ios/Capacitor/Capacitor/Plugins/Filesystem.swift @@ -115,7 +115,9 @@ public class CAPFilesystemPlugin : CAPPlugin { return } } - call.success() + call.success([ + "uri": fileUrl.absoluteString + ]) } catch let error as NSError { handleError(call, error.localizedDescription, error) }