The package has been configured successfully!
See full instructions here.
The configuration for R2 driver relies on certain environment variables and it is usually a good practice to validate the presence of those environment variables.
Open env.ts
file and paste the following code inside it.
R2_ACCESS_KEY_ID: Env.schema.string(),
R2_SECRET_ACCESS_KEY: Env.schema.string(),
R2_BUCKET: Env.schema.string(),
R2_ACCOUNT_ID: Env.schema.string(),
R2_PUBLIC_URL: Env.schema.string.optional(),
Update DRIVE_DISK
- DRIVE_DISK: Env.schema.enum(['local', 's3'] as const),
+ DRIVE_DISK: Env.schema.enum(['local', 's3', 'r2'] as const),
Open the config/drive.ts
and paste the following code snippet inside it.
{
disks: {
// ... other disk
r2: {
driver: 'r2',
visibility: 'private',
key: Env.get('R2_ACCESS_KEY_ID'),
secret: Env.get('R2_SECRET_ACCESS_KEY'),
bucket: Env.get('R2_BUCKET'),
accountId: Env.get('R2_ACCOUNT_ID'),
cdnUrl: Env.get('R2_PUBLIC_URL')
}
}
}
Note that the
cdnUrl
property of this R2 config (which maps to the public URl of your bucket) is required when thevisibility
of the disk ispublic
.
Open the contracts/drive.ts
file. Add the name of the new disk to the DisksList
interface
declare module '@ioc:Adonis/Core/Drive' {
interface DisksList {
// ... other disks
r2: {
config: R2DriverConfig // <-- Make sure to use the `R2DriverConfig` interface
implementation: R2DriverContract // <-- Make sure to use the `R2DriverContract` interface
}
}
}