Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Filesystem Plugin] writeFile should return file URI and webpath URI #1788

Closed
dotNetkow opened this issue Jul 22, 2019 · 3 comments · Fixed by #2484
Closed

[Filesystem Plugin] writeFile should return file URI and webpath URI #1788

dotNetkow opened this issue Jul 22, 2019 · 3 comments · Fixed by #2484

Comments

@dotNetkow
Copy link
Contributor

dotNetkow commented Jul 22, 2019

Currently, after writing a file, you have to use Filesystem.getUri to retrieve the newly created file URI. Could the writeFile function return the URI, which would save a step?

Current:
`
await Filesystem.writeFile({
path: new Date().getTime() + '.jpeg',
data: readFile.data,
directory: FilesystemDirectory.Data
});

const newFile = await Filesystem.getUri({
  directory: FilesystemDirectory.Data,
  path: fileName
});

return newFile.uri;

`

Proposed:
const newFile = await Filesystem.writeFile({
path: new Date().getTime() + '.jpeg',
data: readFile.data,
directory: FilesystemDirectory.Data
});
const uri = newFile.uri;

Additionally, returning the webpath URI from writeFile would be great, too - so the user doesn't have to convert using this:

const webPathUri = Capacitor.convertFileSrc(newFile);

@dotNetkow dotNetkow changed the title [Filesystem Plugin] writeFile should return file URI [Filesystem Plugin] writeFile should return file URI and webpath URI Jul 22, 2019
@jcesarmobile
Copy link
Member

It is like that because the plugin "mimics" the node API.

I'm not opposed to changing the plugin to return the paths, but would like to know @mlynch opinion first.

@bitflower
Copy link

Hi, I would appreciate this change as well.

One question: The uri does change with every app start, right? Is this the expected behaviour or a bug?

For example I have tracked this down before and after app restart:

{
  "NEW_URI": "file:///var/mobile/Containers/Data/Application/7321B7D3-0BA3-475B-AC12-7A70BC4E6F16/Documents/5dc73a223379e923e19bd9b8.png",
  "OLD_URI": "file:///var/mobile/Containers/Data/Application/CF11919B-2C65-458F-B1A3-B7D197A2CE8D/Documents/5dc73a223379e923e19bd9b8.png",
  "IS_DIFFERENT": true
}

See Slack reference: https://getcapacitor.slack.com/archives/C88QP9W56/p1573416440072600

Thanks!

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 12, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants