节点- httptransfer
导言
这个 node-httptransfer 软件包的设计是为了方便和正确地将文件内容从HTTP(S) urls转移到HTTP(S) urls之间以及HTTP(S) urls之间.
下等流 API 允许您将内容从 URL 传输到任何可写流, 并且同样将任何可读流传输到 URL .
高级文件 API 摘要将流移出, 并允许您将内容传输到磁盘上的文件 .
这个 node-httptransfer 软件包需要async/await特性,并使用 节点比对npm 软件包.
要使用块传输能力,上传/下载服务器必须支持范围头.
安装
npm i @adobe/httptransfer
使用流
下载流 :
const { downloadStream } = require('@adobe/httptransfer');
async main() {
const stream = fs.createWriteStream('test.png');
await downloadStream('http://my.server.com/test.png', stream);
}
使用 PUT 上传流 :
const { uploadStream } = require('@adobe/httptransfer');
async main() {
const stream = fs.createReadStream('test.png');
await uploadStream(stream, 'http://my.server.com/test.png');
}
使用文件
下载文件 :
const { downloadFile } = require('@adobe/httptransfer');
async main() {
await downloadFile('http://my.server.com/test.png', 'test.png');
}
使用 PUT 上传文件 :
const { uploadFile } = require('@adobe/httptransfer');
async main() {
await uploadFile('test.png', 'http://my.server.com/test.png');
}
使用 PUT( 由 AEM 多段上传使用) 上传到多个 URL 的文件 :
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
});
}
使用块上传/下行区域同时上传/下行文件
const { downloadFileConcurrently } = require('@adobe/httptransfer');
async main() {
await downloadFile('http://my.server.com/test.png', 'test.png');
}
使用 PUT 上传文件 :
const { uploadFileConcurrently } = require('@adobe/httptransfer');
async main() {
await uploadFile('test.png', 'http://my.server.com/test.png');
}
使用 PUT( 由 AEM 多段上传使用) 上传到多个 URL 的文件 :
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
});
}
使用 PUT 上传多个文件到多个 URL :
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
}
}]);
}
假设 test.png 1,800,000个字节将上传到 http://my.server.com/test.png.1 后80万字节改为 http://my.server.com/test.png.2。 。 。 .
调试
在使用时启用调试输出 node-httptransfer 库,设置 DEBUG 环境变量改为 httptransfer:*。 。 。 .
您也可以指定每个日志级别 ./lib/logger.js (英语),例如:
$ DEBUG='httptransfer:warn' npm run test
测试台
CLI 工具 测试床 用于测试 node-httptransfer 函数。 它支持上传,下载,以及转移文件内容. 它还通过在苍蝇上创建的共享访问签名(SAS)urls支持Azure Blob商店.
该工具并不打算单独有用,只是为了测试新特性或调试问题.
构建
cd testbed/
npm install
Azure 证书
export AZURE_STORAGE_ACCOUNT=<storage account name from https://portal.azure.com>
export AZURE_STORAGE_KEY=<storage key from https://portal.azure.com>
实例
从网站上下载图像 :
node index.js https://website.com/path/to/image.gif image.gif
从 Azure 下载 blob.txt :
node index.js azure://container/path/to/blob.txt blob.txt
上传 blob.txt 到 azure :
node index.js blob.txt azure://container/path/to/blob.txt
以一万字节块上传 blob.txt :
node index.js --max 10000 blob.txt azure://container/path/to/blob.txt
在容器内复制 blob.txt :
node index.js azure://container/path/to/blob.txt azure://container/path/to/target.txt
端到端测试
该模块为验证基本传输功能提供了一些集成式测试 与 Adobe 经验管理器实例。 为了进行测试:
- 创建一个
.env通过遵循在 .env 实例。 。 。 . - 通过执行运行测试
npm run e2e从寄存器的根目录.
端到端块上传/下载测试
如果你想只是运行块上传/下载测试,只需要 Azure 证书数字 :
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>
运行 npm run e2e-block
捐款
欢迎捐款! 读取 贡献指南 更多信息.
许可证发放
这个项目根据Apache V2许可证获得许可. 见 自由主义 更多信息.