@adobe/aio-lib-files

中文文档
4.1.4发布于 2026/05/29Apache-2.0TypeScriptCommonJS近 30 天下载 3万

An abstraction on top of blob cloud storage exposing a file like API

原始使用文档
文档目录10 节
  1. Install
  2. Use
  3. Presigned URL types and usage
  4. Explore
  5. Debug
  6. Adobe I/O Files Store Consistency Guarantees
  7. Troubleshooting
  8. "[StateLib:ERROR_INTERNAL] unknown error response from prov…
  9. Contributing
  10. Licensing

Version Downloads/week Node.js CI License Codecov Coverage

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')

  // init
  // init sdk using OpenWhisk credentials
  const files = await filesLib.init({ ow: { namespace, auth } })
  // init when env vars __OW_API_KEY and __OW_NAMESPACE are set (e.g. when running in an OpenWhisk action)
  const files = await filesLib.init()
  // or if you want to use your own cloud storage account
  const files = await filesLib.init({ azure: { storageAccount, storageAccessKey, containerName } })

  // write private file
  await files.write('mydir/myfile.txt', 'some private content')

  // write publicly accessible file
  await files.write('public/index.html', '<h1>Hello World!</h1>')

   // get file url
  const props = await files.getProperties('public/index.html')
  console.log('props = ', props)
  /*
  props =  { name: 'public/index.html',
    creationTime: 2020-12-09T19:49:58.000Z,
    lastModified: 2020-12-09T19:49:58.000Z,
    etag: '"0x8D89C7B9BB75A6F"',
    contentLength: 21,
    contentType: 'text/html',
    isDirectory: false,
    isPublic: true,
    url:
    'https://jestaiotest.blob.core.windows.net/readme-public/public%2Findex.html' }
  */

  // list all files
  await files.list('mydir/') // with a trailing slash lists a directory, recursively. Returns [] if no files are recursively stored under mydir/.
  await files.list('myfile') // without a trailing slash list returns [fileProps] or [] if it doesn't exist.

  await files.list('/')
  /*
  list =  [ { name: 'mydir/myfile.txt',
    creationTime: 2020-12-09T19:49:57.000Z,
    lastModified: 2020-12-09T19:49:57.000Z,
    etag: '0x8D89C7B9BB165F8',
    contentLength: 20,
    contentType: 'text/plain',
    isDirectory: false,
    isPublic: false,
    url:
     'https://jestaiotest.blob.core.windows.net/readme/mydir%2Fmyfile.txt' },
  { name: 'public/index.html',
    creationTime: 2020-12-09T19:49:58.000Z,
    lastModified: 2020-12-09T19:49:58.000Z,
    etag: '0x8D89C7B9BB75A6F',
    contentLength: 21,
    contentType: 'text/html',
    isDirectory: false,
    isPublic: true,
    url:
     'https://jestaiotest.blob.core.windows.net/readme-public/public%2Findex.html' } ]
  */

  // read
  const buffer = await files.read('mydir/myfile.txt')
  buffer.toString() // 'some private content'

  // pipe read stream to local file (consider using copy below)
  const rdStream = await files.createReadStream('mydir/myfile.txt')
  const stream = rdStream.pipe(fs.createWriteStream('my-local-file.txt'))
  stream.on('finish', () => console.log('done!'))

  // write read stream to remote file (consider using copy below)
  const rdStream = fs.createReadStream('my-local-file.txt')
  await files.write('my/remote/file.txt', rdStream)

  // delete files in 'my/remote/' dir
  await files.delete('my/remote/')
  // delete all public files
  await files.delete('public/')
  // delete all files including public
  await files.delete('/')

  // copy - higher level utility (works likes scp)
  // works for files and directories both remotely and locally, uses streams under the hood
  /// upload a single file
  await files.copy('my-static-app/index.html', 'public/my-static-app/index.html', { localSrc: true })
  /// upload local directory recursively
  await files.copy('my-static-app/', 'public/', { localSrc: true })
  /// download to local directory recursively (works for files as well)
  await files.copy('public/my-static-app/', 'my-static-app-copy', { localDest: true })
  /// copy remote directories around (works for files as well)
  await files.copy('public/my-static-app/', 'my/private/folder')

  // Share private files
  const presignUrl = await files.generatePresignURL('mydir/myfile.txt', { expiryInSeconds: 60 })

  //Share private files with read, write, delete permissions
  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

  1. 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.
  2. 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()

  // getProperties will return both internal and external URLs in return Object
  const props = files.getProperties('public/my-static-app/index.html')

  //generate presign URL with internal URLType
  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.

版本与发布记录

@adobe/aio-lib-files 共发布 37 个版本,首次发布于 2019/09/10;过去 12 个月发布了 2 个版本。

版本发布日期距今
4.1.4latest2026/05/295 个月前
4.1.32026/03/317 个月前
4.1.22025/05/061.5 年前
4.1.12025/04/301.5 年前
4.1.02024/06/262 年前
4.0.12024/02/082 年前

其他发布通道:next → 3.0.1-pre.2024-01-08.sha-040d55a2。

关于 @adobe/aio-lib-files 的常见问题

@adobe/aio-lib-files 是什么?

An abstraction on top of blob cloud storage exposing a file like API

如何安装 @adobe/aio-lib-files?

在项目目录运行 npm install @adobe/aio-lib-files,或使用 pnpm add / yarn add / bun add。

@adobe/aio-lib-files 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adobe/aio-lib-files 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/aio-lib-files 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adobe/aio-lib-files 可以商用吗?

@adobe/aio-lib-files 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/aio-lib-files 的下载量有多少?

根据 npm 官方下载统计,@adobe/aio-lib-files 在 2026/10/05 – 2026/11/03 这 30 天内被下载 29,778 次,日均约 993 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/aio-lib-files 还在维护吗?

最新版本 4.1.4 发布于 2026/05/29(5 个月前);至今共发布 37 个版本,其中过去 12 个月发布了 2 个;首次发布于 2019/09/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。