drive-s3-wrapper
v1.0.8
Published
Agnostic wrapper for AWS S3 ➔ But intended to be used by adonis.js
Downloads
25
Readme
Drive S3 Wrapper
Agnostic wrapper for AWS S3
S3 Config
const s3Config = {
bucket: process.env.S3_BUCKET,
forcePathStyle: true,
endpoint: process.env.S3_ENDPOINT,
region: process.env.S3_REGION,
credentials: {
accessKeyId: process.env.S3_KEY,
secretAccessKey: process.env.S3_SECRET
}
}
Available Methods
put
const { put } = s3Drive(s3Config)
const putResponse = await put('new-file.png')
console.log({ putResponse })
get
const { get } = s3Drive(s3Config)
const getResponse = await get('new-file.png')
console.log({ getResponse })
remove
const { remove } = s3Drive(s3Config)
const removeResponse = await put('new-file.png')
console.log({ removeResponse })
exists
const { exists } = s3Drive(s3Config)
const doesFileExist = await exists('new-file.png')
console.log({ doesFileExist })
Helpers
formatBase64StringIntoUrlData
const { formatBase64StringIntoUrlData, get } = s3Drive(s3Config)
const getImage = await get('new-file.png','base64')
const urlFormattedPNG = formatBase64StringIntoUrlData(getImage,'image/png')
console.log({ urlFormattedPNG })
formatBase64StringIntoUrlData
const { put } = s3Drive(s3Config)
const rawImageUpload = await put(filePath,convertBase64StringToImageData('data:image/png;base64,iVBORw0KG'))
console.log({ rawImageUpload })
determineMimeType
const { determineMimeType } = s3Drive(s3Config)
const filePath = 'i-am-a-file.txt'
const mimeType = determineMimeType(filePath)
console.log({mimeType})