-
Notifications
You must be signed in to change notification settings - Fork 55
Support for make public #139
Comments
It's won't be applicable for all the drivers like local; but gcp and s3 support it. |
php's flysystem library provides a similar feature |
Hey @ojhaujjwal! 👋 We are happily accepting PR! However, I'd recommend to wait until we finish to swap the architecture. |
Thanks @RomainLanz. I will be happy to contribute after it's done. |
Hello everybody! Here is my solution to this problem. In my project I have the structure(AdonisJS V5): /app/Services/Spaces File: index.ts import { StorageManager } from '@slynova/flydrive'
import AmazonWebServicesS3Storage from './AmazonWebServicesS3Storage'
import config from '../../../config/storage'
const storage = new StorageManager(config)
storage.registerDriver('s3', AmazonWebServicesS3Storage)
export default storage File: AmazonWebServicesS3Storage.ts import { NoSuchBucket, FileNotFound, PermissionMissing, UnknownException } from '@slynova/flydrive'
import { AmazonWebServicesS3Storage } from '@slynova/flydrive-s3'
function handleError(err, path, bucket) {
switch (err.name) {
case 'NoSuchBucket':
return new NoSuchBucket(err, bucket)
case 'NoSuchKey':
return new FileNotFound(err, path)
case 'AllAccessDisabled':
return new PermissionMissing(err, path)
default:
return new UnknownException(err, err.name, path)
}
}
export default class MyAmazonWebServicesS3Storage extends AmazonWebServicesS3Storage {
constructor(config) {
super(config)
}
async putPublic(location: string, content: any) {
const params = { Key: location, Body: content, Bucket: this.$bucket, ACL: 'public-read' }
try {
const result = await this.$driver.upload(params).promise()
return { raw: result }
} catch (e) {
throw handleError(e, location, this.$bucket)
}
}
} In a file in a distant world, the method is consumed like this: import Route from '@ioc:Adonis/Core/Route'
import Spaces from 'App/Services/Spaces'
Route.post('spaces', async ({ request }) => {
const file = request.file('name'),
name = file.name
return Spaces.disk('spaces').putPublic(name, file)
}) I extended the original AmazonWebServicesS3Storage class by adding the putPublic method with the 'public-read' ACL rule. It is! MTF solution but functional! 🙃 |
How is the configuration of your StorageManager? |
import Env from '@ioc:Adonis/Core/Env'
import path from 'path'
export const ROOT_PATH = path.resolve(__dirname, '../')
export const STORAGE_PATH = path.resolve(ROOT_PATH, 'resources/storage')
export const PUBLIC_PATH = path.resolve(ROOT_PATH, 'public')
export default {
default: 'local',
disks: {
local: {
driver: 'local',
config: {
root: STORAGE_PATH,
},
},
public: {
driver: 'local',
config: {
root: PUBLIC_PATH,
},
},
spaces: {
driver: 's3',
config: {
key: Env.get('DO_SPACES_KEY'),
secret: Env.get('DO_SPACES_SECRET'),
endpoint: Env.get('DO_SPACES_ENDPOINT'),
bucket: Env.get('DO_SPACES_SPACE'),
region: Env.get('DO_SPACES_REGION'),
},
},
},
} |
Sent a PR #166 |
Is there a way we can support making individual files public?
Use-case: for public images.
The text was updated successfully, but these errors were encountered: