Node.js 将字符串作为文件上载

Node.js 将字符串作为文件上载,node.js,http,file-upload,upload,unirest,Node.js,Http,File Upload,Upload,Unirest,如何使用node.js,通过http post请求将字符串上传为文件 以下是我尝试过的: var unirest = require('unirest'); unirest.post('127.0.0.1/upload') .headers({'Content-Type': 'multipart/form-data'}) .attach('file', 'test.txt', 'some text in file') // Attachment .end(f

如何使用
node.js
,通过http post请求将字符串上传为文件

以下是我尝试过的:

 var unirest = require('unirest');
    unirest.post('127.0.0.1/upload')
     .headers({'Content-Type': 'multipart/form-data'})
     .attach('file', 'test.txt', 'some text in file') // Attachment
    .end(function (response) {
       console.log(response.body);
    });

但是什么也不会发生

您必须从本地文件系统指定一个文件。所以我建议

  • 发送文件

    var unirest = require('unirest');
    unirest.post('127.0.0.1/upload')
        .headers({'Content-Type': 'multipart/form-data'})
        .attach('file', '/tmp/test') 
        .end(function (response) {
           console.log(response.body);
        });
    

  • 必须指定本地文件系统中的文件。所以我建议

  • 发送文件

    var unirest = require('unirest');
    unirest.post('127.0.0.1/upload')
        .headers({'Content-Type': 'multipart/form-data'})
        .attach('file', '/tmp/test') 
        .end(function (response) {
           console.log(response.body);
        });
    

  • 有没有一种方法可以在不先写入文件的情况下上载字符串?有没有一种方法可以在不先写入文件的情况下上载字符串?