@fleekhq/fleek-storage-js

中文文档
1.0.24发布于 2023/02/16ISCCommonJS近 30 天下载 2.1万

JS SDK to interact with Fleek Storage

此软件包已被标记为弃用

We’ve upgraded! The deprecated Fleek Storage SDK is now part of our all-new Fleek Platform SDK, which brings enhanced performance, new features, and broader support for all your development needs. Head to https://www.npmjs.com/package/@fleek-platform/sdk to get started, or visit https://fleek.xyz/docs to learn even more.

原始使用文档
文档目录12 节
  1. get
  2. Input parameters of get
  3. upload
  4. Input parameters of upload
  5. deleteFile
  6. Input parameters of deleteFile
  7. listFiles
  8. Input parameters of listFiles
  9. listBuckets
  10. Input parameters of listBuckets
  11. getFileFromHash
  12. Input parameters of getFileFromHash

Fleek Storage Js

Fleek Storage Js is an SDK to interact with Fleek Storage.

:exclamation: Please do not use this package directly in the browser. Your API secret will be visible to users of that page. If you need to make requests from the client side, please use an S3 SDK directly with pre-signed urls: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html.

yarn add @fleekhq/fleek-storage-js

Importing

The SDK can be imported using an import statement.

import fleekStorage from '@fleekhq/fleek-storage-js'

The SDK can also be imported using a require.

const fleekStorage = require('@fleekhq/fleek-storage-js')

Getting Api Keys

The api key and secret can be generated on the Fleek Web app or from the Fleek CLI.

See Getting an Api Key

Methods

get

The get method is for fetching individual files, either the content or related data, such as the key, hash and publicUrl.

Example of usage:

const myFile = await fleekStorage.get({
  apiKey: 'my-key',
  apiSecret: 'my-secret',
  key: 'my-file-key',
  getOptions: [
    'data',
    'bucket',
    'key',
    'hash',
    'publicUrl'
  ],
})

Input parameters of get

paramtypedescription
apiKeyStringThe api key used for authentication
apiSecretStringThe api secret used for authentication
keyStringThe key identifying the requested file in the bucket
bucketString, optional, defaults to the default account bucketThe name of the bucket containing the file. A bucket is created by default with every Fleek account
getOptionsArray, optional, defaults to ['data']An array specifying what type of information to retrieve concerning the file. Possible values for the array includes data, bucket, hash, key, publicUrl

upload

The upload method uploads a file, identified by a key, to a bucket. The function returns the hash of the file, the publicUrl, the key and the bucket.

Example of usage:

fs.readFile(filePath, async (error, fileData) => {
  const uploadedFile = await fleekStorage.upload({
    apiKey: 'my-key',
    apiSecret: 'my-secret',
    key: 'my-file-key',
    data: fileData,
  });
})


Input parameters of upload

paramtypedescription
apiKeyStringThe api key used for authentication
apiSecretStringThe api secret used for authentication
keyStringThe key identifying the requested file in the bucket
bucketString, optional, defaults to the default account bucketThe name of the bucket containing the file. A bucket is created by default with every Fleek account
dataAnyThe data of the file to be uploaded

deleteFile

The deleteFile method deletes a file, identified by its key and bucket. The function returns the key and bucket of the deleted file if successful. If the file does not exist, the method will still execute successfully.

Example of usage:

  await fleekStorage.deleteFile({
    apiKey: 'my-key',
    apiSecret: 'my-secret',
    key: 'my-file-key',
    bucket: 'my-bucket',
  });

Input parameters of deleteFile

paramtypedescription
apiKeyStringThe api key used for authentication
apiSecretStringThe api secret used for authentication
keyStringThe key identifying the file in the bucket
bucketString, optional, defaults to the default account bucketThe name of the bucket containing the file. A bucket is created by default with every Fleek account

listFiles

The listFiles method is for fetching information about all files in a bucket such as the key, hash and publicUrl.

Example of usage:

const files = await fleekStorage.listFiles({
  apiKey: 'my-key',
  apiSecret: 'my-secret',
  prefix: 'my-folder',
  getOptions: [
    'bucket',
    'key',
    'hash',
    'publicUrl'
  ],
})

Input parameters of listFiles

paramtypedescription
apiKeyStringThe api key used for authentication
apiSecretStringThe api secret used for authentication
bucketString, optional, defaults to the default account bucketThe name of the bucket containing the file. A bucket is created by default with every Fleek account
prefixString, optional, defaults to the empty stringThe name of the folder you want to list files in. Can be used to recurse through the folder structure in Fleek Storage
getOptionsArray, optional, defaults to ['key', 'bucket', 'publicUrl']An array specifying what type of information to retrieve concerning the file. Possible values for the array includes bucket, hash, key, publicUrl

listBuckets

The listBuckets method returns an array of bucket names associated with the api key's account.

Example of usage:

const buckets = await fleekStorage.listBuckets({
  apiKey: 'my-key',
  apiSecret: 'my-secret',
})

Input parameters of listBuckets

paramtypedescription
apiKeyStringThe api key used for authentication
apiSecretStringThe api secret used for authentication

getFileFromHash

getFileFromHash is a utility function that downloads a file's data from Fleek's IPFS gateway using the hash. The key and secret is not required since the gateway is publicly available.

Example of usage:

const myFile = await fleekStorage.getFileFromHash({
  hash: 'bafybeige4bhzjvrptn7fdz7mqgigzoczcliqpuo7km4jm7vgjg2pbmuhna',
  getFileFromHashOptions: [
    'buffer',
  ],
})

Input parameters of getFileFromHash

paramtypedescription
hashStringThe hash of the requested file
getFileFromHashOptionsArray, optional, defaults to []An array specifying additional options when it comes to fetching by hash. Possible values for the array includes buffer (this returns the whole file at once instead of chunks)

版本与发布记录

@fleekhq/fleek-storage-js 共发布 28 个版本,首次发布于 2020/06/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.24latest2023/02/163 年前
1.0.232022/12/293 年前
1.0.222022/07/214 年前
1.0.212022/03/014 年前
1.0.202021/09/175 年前
1.0.192021/09/165 年前

其他发布通道:beta → 1.0.18-beta.3。

关于 @fleekhq/fleek-storage-js 的常见问题

@fleekhq/fleek-storage-js 是什么?

JS SDK to interact with Fleek Storage注意:该包已被作者标记为弃用——We’ve upgraded! The deprecated Fleek Storage SDK is now part of our all-new Fleek Platform SDK, which brings enhanced performance, new features, and broader support for all your development needs. Head to https://www.npmjs.com/package/@fleek-platform/sdk to get started, or visit https://fleek.xyz/docs to learn even more.

如何安装 @fleekhq/fleek-storage-js?

在项目目录运行 npm install @fleekhq/fleek-storage-js,或使用 pnpm add / yarn add / bun add。

@fleekhq/fleek-storage-js 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fleekhq__fleek-storage-js 是否存在。

@fleekhq/fleek-storage-js 支持 ESM 还是 CommonJS?

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

@fleekhq/fleek-storage-js 可以商用吗?

@fleekhq/fleek-storage-js 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fleekhq/fleek-storage-js 的下载量有多少?

根据 npm 官方下载统计,@fleekhq/fleek-storage-js 在 2026/10/15 – 2026/11/13 这 30 天内被下载 20,772 次,日均约 692 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fleekhq/fleek-storage-js 还在维护吗?

最新版本 1.0.24 发布于 2023/02/16(3 年前);至今共发布 28 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/12。作者已将其标记为弃用,新项目建议寻找替代方案。