如何将表单数据中的缓冲区发送到SignServer? [英] How to send a buffer in form-data to SignServer?

查看:82
本文介绍了如何将表单数据中的缓冲区发送到SignServer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在内存中有一个文件(在缓冲区中),该文件在文件系统上不存在(所以我不能只是流式传输).

I have a file in memory (in a buffer), it doesn't exist on the file system (so I can't just stream that).

我正在尝试将其发送到 SignServer 使用HTTP.

I'm trying to send it to SignServer using HTTP.

这是我尝试执行的操作:

Here's how I try to do it:

var formdata = require('form-data'); var form = new formdata();

form.append('workerName', 'PDFSigner');
form.append('data', file_buffer);
// or
// escape(file_buffer.toString('binary'))
// or
// file_buffer.toString('binary') (without escaping)

var request = form.submit('http://localhost:8080/signserver/process', function(err, res) {});

当我尝试附加file_buffer时,SignServer说data为空:

When I try appending file_buffer SignServer says that data is empty:

状态400-上传中缺少文件内容

Status 400 - Missing file content in upload

当我尝试附加escape(file_buffer.toString('binary'))时(如

When I try appending escape(file_buffer.toString('binary')) (as suggested in How do I send a buffer in an HTTP request?) it's the same story.

当我尝试附加file_buffer.toString('binary')时,node.js崩溃时说:

When I try appending file_buffer.toString('binary') node.js crashes saying:

节点:../src/stream_base.cc:157 int节点:: StreamBase :: Writev(const v8 :: FunctionCallbackInfo&):断言`(offset)< =(storage_size)'失败.

node: ../src/stream_base.cc:157 int node::StreamBase::Writev(const v8::FunctionCallbackInfo&): Assertion `(offset) <= (storage_size)' failed.

已中止(核心已弃用)

如何在Node.JS中通过HTTP(多部分/表单数据)正确发送文件(缓冲区)?

How do I correctly send the file (buffer) through HTTP (multipart/form-data) in Node.JS?

推荐答案

您明确需要为data字段设置filename,否则缓冲区不会作为文件上传:

You explicitly need to set a filename for the data field, otherwise the buffer isn't uploaded as a file:

form.append('data', file_buffer, { filename : 'document.pdf' });

在此处对此文件进行了记录(尽管不是很清楚): https://github.com/form-data/form-data#alternative-submission-methods (向下滚动到第四个示例).

This is documented (albeit not very clearly) here: https://github.com/form-data/form-data#alternative-submission-methods (scroll down to the fourth example).

这篇关于如何将表单数据中的缓冲区发送到SignServer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆