node.js - 如何在 Nodejs 中将字符串作为读取流对象传递?

我正在为第 3 方 API 尝试多重导入功能,我需要在其中传递一个 json 文件读取流。

但我的 api 中已经有一组用户数据,我需要将其作为读取流传递。

我已经尝试过的选项。

  1. fs.createReadStream

fs.createReadStream(Buffer.from(JSON.stringify('[{ user: "data"}]')));

createReadStream not accepting Buffer & returns

ENOENT: no such file or directory, open

  1. require('stream').Readable

    const Readable = require('stream').Readable; const readStream = new Readable(); readStream._read = () => {}; readStream.push(JSON.stringify(u)); readStream.push(null);

Read stream gives me "Invalid multipart payload format" error in my request

请找到我为多用户文件上传传递的请求对象

{
  "url": "",
  "method": "POST",
  "headers": {},
  "formData": {
    "userFile": ReadStream
  }
}

如有任何建议,我们将不胜感激

最佳答案

您可以像这样从字符串创建可读流:

import { Readable } from 'stream';
// OR: const { Readable } = require('stream');

const stream = Readable.from("This is the stream content");

https://stackoverflow.com/questions/54423322/

相关文章:

python - 使用聚类从文档列表中找出所有潜在的相似文档

c# - 调用 Assembly.ReflectionOnlyLoadFrom 时出现 System

spring-boot - 如何在 Spring Security oauth2 中调试重定向 ur

typo3 - 使用流体创建数组和对象 f :variable

angular - 如何在 ngrx 效果中使用 LatestFrom 进行单元测试

java - soap 请求 java 中缺少 header

gitlab - 如何从私有(private) gitlab repo 创建公开发布?

clojure - 全栈 Clojure : How to get a Browser REPL a

wpf - ListView 组标题显示多次

c# - 未续订 Azure 服务总线消息锁?