You are viewing a plain text version of this content. The canonical link for it is here.
Posted to devnull@infra.apache.org by "Domvel (GitHub)" <gi...@apache.org> on 2018/08/23 13:51:03 UTC
[GitHub] [cordova-plugin-file] Domvel opened issue #246: writeFile
create path (deep) if not exists.
How to create a full path on or before writeFile? I already tried several variations and going insane.
I tried it with `getFile` and options `create` and with `createDir`. Nothing works.
```js
// How to create the full path if not exist?
file.writeFile(file.externalDataDirectory, 'subfolder/another/file.txt', blob, {replace: true});
```
Maybe a option `createPath` or just `create` for `writeFile` is maybe not the worst idea?
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Suddenly this works now.
```ts
await this.file.createDir(this.file.externalDataDirectory, 'myfolder', true);
```
I already tried it yesterday without success. It's weird that you have to set "replace" flag. This function should create a folder if not exist and should not fail if it already exists. Therefore use the methods checkDir and for replace removeDir.
I have no idea what was wrong in the last days. But I found a Android bug:
The "media storage" has a cache problem. If you create a folder on the sd-card (virtual: internal memory) you can't see this folder on Windows if the device is connected as Media Storage (MTP) until you clear the cache in settings > app > media storage. Otherwise the just created folders / files are not visible. Also after USB replug. This is really weak. Maybe the plugin has to trigger the FS to update the cache?
Closed, because I can create directories now. It's not quite perfect. But ok.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] janpio commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "janpio (GitHub)" <gi...@apache.org>.
I suggest you create a simple reproduction app with Cordova only (`cordova create`) and implement your problem using plain JS functionality from this plugin. Then you know if it works this way. If not, your issue here is valid and something can be done about it. If it does, then the problem is somewhere between the plugin and what ends up as your code (Ionic Native, Promise stuff, ...).
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I want this result:
Before: `<sdcard>/Android/data/<app-id>/files`
After: `<sdcard>/Android/data/<app-id>/files/subfolder/another/file.txt`
(externalDataDirectory == '<sdcard>/Android/data/<app-id>/files')
I expected an option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
The documentation is not the best I ever seen. ;)
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I want this result:
Before: `<sdcard>/Android/data/<app-id>/files`
After: `<sdcard>/Android/data/<app-id>/files/subfolder/another/file.txt`
(externalDataDirectory == `<sdcard>/Android/data/<app-id>/files`)
I expected an option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
The documentation is not the best I ever seen. ;)
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel closed issue #246: writeFile
create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
[ issue closed by Domvel ]
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
This snippet also does not work.
```ts
let rootDir = await this.file.resolveDirectoryUrl(this.file.externalDataDirectory);
await this.file.getDirectory(rootDir, 'myFolder', { create: true });
```
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
This
```ts
public async createDirectory(dirPath: string): Promise<void> {
const path = await this.file.resolveDirectoryUrl(this.file.externalDataDirectory);
await new Promise((resolve, reject) => {
path.getDirectory(dirPath, { create: true }, resolve, reject);
});
}
```
`dirPath ='myfolder';`
does not work. btw. you see that the function `getDirectory` is not wrapped by the ionic. So I wrapped it in a promise for async-await.
The code above is a simplified version of the example of the documentation. Just in typescript and the ionic wrapper.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I want this result:
Before: `<sdcard>/Android/data/<app-id>/files`
After: `<sdcard>/Android/data/<app-id>/files/subfolder/another/file.txt`
(externalDataDirectory == '<sdcard>/Android/data/<app-id>/files'
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] janpio commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "janpio (GitHub)" <gi...@apache.org>.
`this.file` being the Ionic Native wrapper for `cordova-plugin-file` here?
Can you share the code you use to create multiple folders deep?
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] janpio commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "janpio (GitHub)" <gi...@apache.org>.
What platform are you on?
See the documentation: https://github.com/apache/cordova-plugin-file#create-directories-
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
(`<sdcard>/Android/data/<app-id>/files`)
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Do I need `window.resolveLocalFileSystemURL` or similar with cordova? On ionic I wrote a file to externalDataDirectory without doing that and it worked.
Any examples? The docs of this plugin is not enough.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Do I need `window.resolveLocalFileSystemURL` or similar with cordova?
I also found examples on web with `window.requestFileSystem`.
On ionic I wrote a file to externalDataDirectory without doing that and it worked.
Any examples? The docs of this plugin is not enough. Horrible.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I want this result:
Before: `<sdcard>/Android/data/<app-id>/files`
After: `<sdcard>/Android/data/<app-id>/files/subfolder/another/file.txt`
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Suddenly this works now.
```ts
await this.file.createDir(this.file.externalDataDirectory, 'myfolder', true);
```
I already tried it yesterday without success. It's weird that you have to set "replace" flag. This function should create a folder if not exist and should not fail if it already exists. Therefore use the methods checkDir and for replace removeDir.
I have no idea what was wrong in the last days. But I found a Android bug:
The "media storage" has a cache problem. If you create a folder on the sd-card (virtual: internal memory) you can't see this folder on Windows if the device is connected as Media Storage (MTP) until you clear the cache in settings > app > media storage. This is really weak. Maybe the plugin has to trigger the FS to update the cache?
Closed, because I can create directories now. It's not quite perfect. But ok.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
(`<sdcard>/Android/data/<app-id>/files` -> `<sdcard>/Android/data/<app-id>/files/subfolder/another/file.txt`)
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Thanks for fast response. 🙂
I'm on Android with Ionic Angular. The example you posted is confusing and does not work in my case.
I want to write a file to the path `subfolder/another/file.txt` on sd storage path `externalDataDirectory` (see my first post).
Btw. when I create the path manually on the sd card, it works. So the writeFile method and the directory works. The only failure is to create the path `subfolder/another` on `externalDataDirectory` if not exist.
I want this result:
Before: `<sdcard>/Android/data/<app-id>/files`
After: `<sdcard>/Android/data/<app-id>/files/subfolder/another/file.txt`
(externalDataDirectory == '<sdcard>/Android/data/<app-id>/files')
I expected a option for writeFile to create this (deep) path. Or check if this directory and create it manually by the existing methods of this plugin. But nothing worked so far.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
This
```ts
public async createDirectory(dirPath: string): Promise<void> {
const path = await this.file.resolveDirectoryUrl(this.file.externalDataDirectory);
await new Promise((resolve, reject) => {
path.getDirectory(dirPath, { create: true }, resolve, reject);
});
}
```
`dirPath ='myfolder';`
does not work. btw. you see that the function `getDirectory` is not wrapped by the ionic. So I wrapped it in a promise for async-await.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
This
```ts
public async createDirectory(dirPath: string): Promise<void> {
const path = await this.file.resolveDirectoryUrl(this.file.externalDataDirectory);
await new Promise((resolve, reject) => {
path.getDirectory(dirPath, { create: true }, resolve, reject);
});
}
```
`dirPath ='myfolder';`
does not work. btw. you see that the function `getDirectory` is not wrapped by the ionic. So I wrapped it in a promise for async-await.
The code above is a simplified version of the example of the documentation. Just in typescript and the ionic wrapper.
Error: `code: 9` `message: "INVALID_MODIFICATION_ERR"`
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cordova-plugin-file] Domvel commented on issue #246:
writeFile create path (deep) if not exists.
Posted by "Domvel (GitHub)" <gi...@apache.org>.
Do I need `window.resolveLocalFileSystemURL` or similar with cordova?
I also found examples on web with `window.requestFileSystem`. The plugin should handle this.
On ionic I wrote a file to externalDataDirectory without doing that and it worked.
Any examples? The docs of this plugin is not enough. Horrible.
[ Full content available at: https://github.com/apache/cordova-plugin-file/issues/246 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org