Node implementation uploads files to another server

Source: Internet
Author: User

1, needle

NPM Install needle

var needle = require (' needle '); var data = {    ' bar ',    './images/2.png ', Content_Type: ' Image/png ' }}needle.post (truefunction(err, resp, body) {    //  needle'll read the file and include it in the Form-data    as binary console.log (err, resp, body)});

2. Request

NPM Install request

varRequest = require (' request '));varFormData = {    //Pass A simple key-value pairMy_field: ' My_value ',    //Pass data via buffersMy_buffer:NewBuffer ([1, 2, 3]),    //Pass data via StreamsMy_file:fs.createReadStream ('./images/2.png ')),};request.post ({URL:' Http://xxx/upload_v_article ', formdata:formdata},functionOptionalcallback (err, HttpResponse, body) {if(err) {returnConsole.error (' Upload failed: ', err); } console.log (' Upload successful! Server responded with: ', body);});

Node implementation uploads files to another server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.