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

feat: Filesystem.copy should return new filepath #252

Closed
dotNetkow opened this issue Dec 11, 2020 · 2 comments
Closed

feat: Filesystem.copy should return new filepath #252

dotNetkow opened this issue Dec 11, 2020 · 2 comments
Labels
enhancement New feature or request platform: android platform: ios platform: web type: feature request A new feature, enhancement, or improvement

Comments

@dotNetkow
Copy link

Feature Request

Description

After copying a file to a new location using Filesystem.copy, the CopyResult object returned is an empty object. It's difficult to determine the full filepath to that new location, so I'd like to request that the path gets added to the CopyResult.

My use case is moving a photo taken with the official Camera plugin (stored in temp storage, "cache" folder) to permanent storage (data directory). Complete example in the Ionic First App tutorial, where I'm converting the photo to base64 then using FS.writeFile(). It'd require much less code to use copy() instead.

Here's an example use case:

const cameraPhoto = await Camera.getPhoto({
  resultType: CameraResultType.Uri
});

// path is: file:///data/user/0/io.ionic.pg.ng.cap/cache/JPEG_20201211_140602.jpg
// extract just the filename for the Filesystem API
const photoFilename = cameraPhoto.path.substr(cameraPhoto.path.lastIndexOf('/') + 1);
// photoFilename = JPEG_20201211_140602.jpg

const savedFile = await Filesystem.copy({
   from: photoFilename,  
   directory: FilesystemDirectory.Cache,
    to: "newPhoto.jpg",
    toDirectory: FilesystemDirectory.Data
});

// empty object!
console.log(savedFile);

The challenge is understanding what the underlying path of the new file actually is, which is required for many use cases such as displaying the newly captured photo in an app or saving that path for retrieval later (in a database, etc).

Platform(s)

web, ios, android

Preferred Solution

const savedFile = await Filesystem.copy({
   from: photoFilename,  
   directory: FilesystemDirectory.Cache,
    to: "newPhoto.jpg",
    toDirectory: FilesystemDirectory.Data
});

// no longer empty, path prop added that points to complete filepath
console.log(savedFile.path);
// path is: file:///data/user/0/io.ionic.pg.ng.cap/files/myPhoto.jpg
@dotNetkow dotNetkow changed the title feat: Filesystem.copy should return new filepath and parse paths for the developer feat: Filesystem.copy should return new filepath Dec 12, 2020
@jcesarmobile jcesarmobile transferred this issue from ionic-team/capacitor Feb 12, 2021
@jcesarmobile jcesarmobile added enhancement New feature or request and removed triage labels Jun 18, 2021
@jcesarmobile jcesarmobile added the type: feature request A new feature, enhancement, or improvement label Apr 1, 2022
@jcesarmobile
Copy link
Member

4.0.0 beta 0 now returns the new file path

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 30, 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 the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request platform: android platform: ios platform: web type: feature request A new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

3 participants