@adobe/httptransfer

中文文档
5.0.0发布于 2025/03/20Apache-2.0CommonJS近 30 天下载 1.6万

Efficient File Transfer Module for NodeJS

原始使用文档
文档目录14 节
  1. Introduction
  2. Installation
  3. Using streams
  4. Using files
  5. Using block upload/downland to upload/download files concur…
  6. Debugging
  7. Testbed
  8. Build
  9. Azure credentials
  10. Examples
  11. End-to-End Tests
  12. End-to-End block upload/download Tests
  13. Contributing
  14. Licensing

node-httptransfer

Version

Introduction

The node-httptransfer package is designed to easily and correctly transfer file content from HTTP(S) urls to HTTP(S) urls and between HTTP(S) urls.

The lower-level stream API allows you to transfer content from a URL to any writable stream, and similarly transfer any readable stream to a URL.

The higher-level file API abstracts away the streams and allows you to transfer content to/from files on disk.

The node-httptransfer package requires the async/await features and is built using the node-fetch-npm package.

To use block transfer capabilities, the upload/download servers must support the range header.

Installation

npm i @adobe/httptransfer

Using streams

Download a stream:

const { downloadStream } = require('@adobe/httptransfer');
async main() {
    const stream = fs.createWriteStream('test.png');
    await downloadStream('http://my.server.com/test.png', stream);
}

Upload a stream using PUT:

const { uploadStream } = require('@adobe/httptransfer');
async main() {
    const stream = fs.createReadStream('test.png');
    await uploadStream(stream, 'http://my.server.com/test.png');
}

Using files

Download a file:

const { downloadFile } = require('@adobe/httptransfer');
async main() {
    await downloadFile('http://my.server.com/test.png', 'test.png');
}

Upload a file using PUT:

const { uploadFile } = require('@adobe/httptransfer');
async main() {
    await uploadFile('test.png', 'http://my.server.com/test.png');
}

Upload a file to multiple URLs using PUT (used by AEM multi-part upload):

const { uploadAEMMultipartFile } = require('@adobe/httptransfer');
async main() {
    await uploadAEMMultipartFile('test.png', {
        urls: [ "http://my.server.com/test.png.1", "http://my.server.com/test.png.2" ],
        maxPartSize: 1000000
    });
}

Using block upload/downland to upload/download files concurrently

const { downloadFileConcurrently } = require('@adobe/httptransfer');
async main() {
    await downloadFile('http://my.server.com/test.png', 'test.png');
}

Upload a file using PUT:

const { uploadFileConcurrently } = require('@adobe/httptransfer');
async main() {
    await uploadFile('test.png', 'http://my.server.com/test.png');
}

Upload a file to multiple URLs using PUT (used by AEM multi-part upload):

const { uploadMultiPartFileConcurrently } = require('@adobe/httptransfer');
async main() {
    await uploadMultiPartFileConcurrently('test.png', {
        urls: [ "http://my.server.com/test.png.1", "http://my.server.com/test.png.2" ],
        maxPartSize: 1000000
    });
}

Upload multiple files to multiple URLs using PUT:

const { uploadFilesConcurrently } = require('@adobe/httptransfer');
async main() {
    await uploadFilesConcurrently([{
        filepath: 'file1.png',
        target: {
            urls: [ "http://my.server.com/file1.png.1", "http://my.server.com/file1.png.2" ],
            maxPartSize: 1000000
        }
    }], {
        filepath: 'file2.png',
        target: {
            urls: [ "http://my.server.com/file2.png.1", "http://my.server.com/file2.png.2" ],
            maxPartSize: 1000000
        }
    }]);
}

Assuming test.png is 1,800,000 bytes this will upload the first 1,000,000 bytes to http://my.server.com/test.png.1 and the next 800,000 bytes to http://my.server.com/test.png.2.

Debugging

To enable debug output when using node-httptransfer library, set the DEBUG environment variable to httptransfer:*. You can also specify a specific loglevel per ./lib/logger.js, e.g.:

$ DEBUG='httptransfer:warn' npm run test

Testbed

A CLI tool testbed is provided to try out the node-httptransfer functionality. It supports uploading, downloading, and transferring file content. It also supports Azure Blob stores through Shared Access Signature (SAS) urls created on the fly.

The tool is not intended to be useful on its own, only to test out new features or debug issues.

Build

cd testbed/
npm install

Azure credentials

export AZURE_STORAGE_ACCOUNT=<storage account name from https://portal.azure.com>
export AZURE_STORAGE_KEY=<storage key from https://portal.azure.com>

Examples

Download an image from a website:

node index.js https://website.com/path/to/image.gif image.gif

Download blob.txt from azure:

node index.js azure://container/path/to/blob.txt blob.txt

Upload blob.txt to azure:

node index.js blob.txt azure://container/path/to/blob.txt

Upload blob.txt in 10,000 byte blocks:

node index.js --max 10000 blob.txt azure://container/path/to/blob.txt

Copy blob.txt within a container:

node index.js azure://container/path/to/blob.txt azure://container/path/to/target.txt

End-to-End Tests

The module provides some integration-style tests for verifying basic transfer functionality with an Adobe Experience Manager instance. To run the tests:

  • Create a .env file by following the instructions in .env_example.
  • Run the tests by executing npm run e2e from the root directory of the repository.

End-to-End block upload/download Tests

If you want to just run the block upload/download tests, you only need Azure credentials:

export AZURE_STORAGE_ACCOUNT=<storage account name from https://portal.azure.com>
export AZURE_STORAGE_KEY=<storage key from https://portal.azure.com>
export AZURE_STORAGE_CONTAINER_NAME=<storage container name>

The run npm run e2e-block

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/httptransfer 共发布 37 个版本,首次发布于 2020/04/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2025/03/201.6 年前
4.0.12025/03/201.6 年前
4.0.02024/06/012 年前
3.4.12023/07/263 年前
3.4.02023/06/033 年前
3.3.12023/05/263 年前

关于 @adobe/httptransfer 的常见问题

@adobe/httptransfer 是什么?

Efficient File Transfer Module for NodeJS

如何安装 @adobe/httptransfer?

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

@adobe/httptransfer 支持 TypeScript 吗?

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

@adobe/httptransfer 支持 ESM 还是 CommonJS?

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

@adobe/httptransfer 可以商用吗?

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

@adobe/httptransfer 的下载量有多少?

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

@adobe/httptransfer 还在维护吗?

最新版本 5.0.0 发布于 2025/03/20(1.6 年前);至今共发布 37 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/04/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。