Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

getUrl method across all drivers #102

Open
rodrigoroma opened this issue Aug 4, 2019 · 3 comments
Open

getUrl method across all drivers #102

rodrigoroma opened this issue Aug 4, 2019 · 3 comments

Comments

@rodrigoroma
Copy link

Hi!

Looking at AwsS3.js code, I found getUrl and getSignedUrl methods but I couldn't find those methods on LocalFileSystem.js driver. It would be interesting to have a standartized getUrl method across all drivers.

The local driver should accept a baseUrl option in its configuration object to determine the base URL to be preppended in the file being acessed. Drivers that don't support acessing the file through a URL could throw an exception.

To pass additional configuration to the getUrl method (like if the URL should be signed or not or the expiry of link) it could use an options object as a second parameter. Some parameters could be ignored depending on the driver.

x.getUrl("file.jpg", {
  signedUrl: true,
  expiry: 600
});
@RomainLanz
Copy link
Member

RomainLanz commented May 19, 2020

Hey @rodrigoroma! 👋

Thinking about this, we could add something like the following:

disks: {
    driver: 'local',
    root: process.cwd(),
    computeUrl: (location: string) => {
      // ...
    }
  },
}

We give the power to the user to add a callback method inside their configuration. This method will let you compute the URL with what you need and we will use that to return it inside the LocalStorage driver.

What do you think?

@rodrigoroma
Copy link
Author

Hi @RomainLanz!

It seens good.

@amraei
Copy link

amraei commented Jun 24, 2021

@RomainLanz Why not simply concatenating it to a prefix?

disks: {
    driver: 'local',
    root: process.cwd(),
    url: https://domain.com
  },
} 

and then:

Drive.disk().getUrl('/path/to/file')
// returns "https://domain.com/path/to/file"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants