@adobe/adobeio-cna-cloud-storage 中文文档教程

发布于 3年前 浏览 6 项目主页 更新于 3年前

版本 下载/周 构建状态 许可”></a> 
  <a href=Codecov Coverage

Adobe I/O CNA Storage SDK

云 blob 存储之上的 JavaScript 抽象,公开了类似 API 的文件系统。

您可以使用 Adob​​e I/O Runtime(又名 OpenWhisk)初始化 SDK 证书。

或者,您可以携带自己的云存储密钥。 但是请注意,作为 目前我们只支持 Azure Blob Storage。 AWS S3 是待办事项列表中的下一个 并将很快面世。

Install

npm install @adobe/adobeio-cna-cloud-storage

Use

  const storageSDK = require('@adobe/adobeio-cna-cloud-storage')

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

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

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

  // get file url
  const props = await storage.getProperties('public/index.html')
  props.url

  // list all files
  await storage.list('/') // ['mydir/myfile.txt', 'public/index.html']

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

  // pipe read stream to local file
  const rdStream = await storage.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
  const rdStream = fs.createReadStream('my-local-file.txt')
  await storage.write('my/remote/file.txt', rdStream)

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

  // copy
  // upload local directory
  await storage.copy('my-static-app/', 'public/', { localSrc: true })
  // download to local directory
  await storage.copy('public/my-static-app/', 'my-static-app-copy', { localDest: true })
  // copy files around cloud storage
  await storage.copy('public/my-static-app/', 'my/private/folder')

Explore

goto API

Contributing

欢迎贡献! 阅读贡献指南了解更多信息。

Licensing

这个项目是根据 Apache V2 许可证获得许可的。 有关详细信息,请参阅许可证

Version Downloads/week Build Status License Codecov Coverage

Adobe I/O CNA Storage SDK

A 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. AWS S3 is the next on the todo list and will soon be available.

Install

npm install @adobe/adobeio-cna-cloud-storage

Use

  const storageSDK = require('@adobe/adobeio-cna-cloud-storage')

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

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

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

  // get file url
  const props = await storage.getProperties('public/index.html')
  props.url

  // list all files
  await storage.list('/') // ['mydir/myfile.txt', 'public/index.html']

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

  // pipe read stream to local file
  const rdStream = await storage.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
  const rdStream = fs.createReadStream('my-local-file.txt')
  await storage.write('my/remote/file.txt', rdStream)

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

  // copy
  // upload local directory
  await storage.copy('my-static-app/', 'public/', { localSrc: true })
  // download to local directory
  await storage.copy('public/my-static-app/', 'my-static-app-copy', { localDest: true })
  // copy files around cloud storage
  await storage.copy('public/my-static-app/', 'my/private/folder')

Explore

goto API

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.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文