
Adobe I/O Lib Files
A Node JavaScript abstraction on top of cloud blob storages exposing a file-system like API.
You can initialize the SDK with your Adobe I/O Runtime (a.k.a OpenWhisk)
credentials.
Alternatively, you can bring your own cloud storage keys. Note however, that as
of now we only support Azure Blob Storage.
Please note that currently you must be a customer of Adobe Developer App Builder to use this library. App Builder is a complete framework that enables enterprise developers to build and deploy custom web applications that extend Adobe Experience Cloud solutions and run on Adobe infrastructure.
Install
npm install @adobe/aio-lib-files
Use
const filesLib = require('@adobe/aio-lib-files')
const files = await filesLib.init({ ow: { namespace, auth } })
const files = await filesLib.init()
const files = await filesLib.init({ azure: { storageAccount, storageAccessKey, containerName } })
await files.write('mydir/myfile.txt', 'some private content')
await files.write('public/index.html', '<h1>Hello World!</h1>')
const props = await files.getProperties('public/index.html')
console.log('props = ', props)
await files.list('mydir/')
await files.list('myfile')
await files.list('/')
const buffer = await files.read('mydir/myfile.txt')
buffer.toString()
const rdStream = await files.createReadStream('mydir/myfile.txt')
const stream = rdStream.pipe(fs.createWriteStream('my-local-file.txt'))
stream.on('finish', () => console.log('done!'))
const rdStream = fs.createReadStream('my-local-file.txt')
await files.write('my/remote/file.txt', rdStream)
await files.delete('my/remote/')
await files.delete('public/')
await files.delete('/')
await files.copy('my-static-app/index.html', 'public/my-static-app/index.html', { localSrc: true })
await files.copy('my-static-app/', 'public/', { localSrc: true })
await files.copy('public/my-static-app/', 'my-static-app-copy', { localDest: true })
await files.copy('public/my-static-app/', 'my/private/folder')
const presignUrl = await files.generatePresignURL('mydir/myfile.txt', { expiryInSeconds: 60 })
const rwdPresignUrl = await files.generatePresignURL('mydir/myfile.txt', { expiryInSeconds: 60, permissions: 'rwd' })
Presigned URL types and usage
File SDK supports two types of presigned URLs to access a file
- External - CDN based URLs which can be accessed from anywhere, assuming right pre-sign permissions for private files. You can use this type of URLs to provide access to your files to external systems and APIs for remote compute use-cases.
- Internal - Direct URLs to file storage. These URLs work only if used within Adobe I/O Runtime actions. You can use this type of URLs to chain worker actions that are processing the same file from different Runtime namespaces. As there is no CDN indirection, using this type of URL will improve the performance of your Runtime actions.
Files.getProperties returns both URL types (external as url, and internal as internalUrl) for a given file path
Files.generatePresignURL supports UrlType as option to generate presign URL of given type
See usage example below -
const { init, UrlType } = require('@adobe/aio-lib-files')
const files = await init()
const props = files.getProperties('public/my-static-app/index.html')
const internalPresignUrl = await files.generatePresignURL('mydir/myfile.txt', { expiryInSeconds: 60, permissions: 'rwd', urltype: UrlType.internal })
Explore
goto
API
Debug
set DEBUG=@adobe/aio-lib-files*
to see debug logs.
Adobe I/O Files Store Consistency Guarantees
Strong consistency is guaranteed for all operations and across instances of the files sdk (returned by filesLib.init()
).
Troubleshooting
"[StateLib:ERROR_INTERNAL] unknown error response from provider with status: unknown"
- when using
@adobe/aio-lib-files
in an action bundled with webpack please make sure to turn off minification and enable resolving of es6 modules. Add the following lines to your webpack config:
optimization: {
minimize: false
},
resolve: {
extensions: ['.js'],
mainFields: ['main']
}
Contributing
Contributions are welcomed! Read the Contributing Guide for more information.
Licensing
This project is licensed under the Apache V2 License. See LICENSE for more information.