Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:14:59+00:00 2026-06-16T01:14:59+00:00

In Node.js, I’m using the code below to download the file from the server.

  • 0

In Node.js, I’m using the code below to download the file from the server. The API call is success. After I save the ‘data’ to the local file with the ‘binary’ encoding, the local file can’t be opened by the corresponding software. I compared the file size of the local file and the server file. There is a minor difference.

I can’t find where I’m wrong. Does the OAuth library supports the file download?

var OAuth = require('oauth').OAuth;

var consumer = new OAuth('',
            null,
            consumer_key, consumer_key_secret, '1.0',
            null, 'HMAC-SHA1');

consumer.get(url
        , oauth_token, ooauth_token_secret
        , function (err, data, response){
            var filename = path.join(__dirname, "test.dwg");
            var file = fs.createWriteStream(filename);

            console.log('Data length: ' + data.length);

            file.write(data, 'binary', function(err){                       
                console.log('Complete');
            });             
        }       
    );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:15:00+00:00Added an answer on June 16, 2026 at 1:15 am

    I got the solution after some testing.

    The reason of this issue is we are receiving the http body in ‘utf8’ encoding. Use the ‘binary’ encoding can fix it.

    The oauth module only supports the utf8 encoding when get the response. This is hard code in file “oatuh\lib\oauth.js” at “Line # 375, response.setEncoding(‘utf8’);”.

    Even though I set the encoding as the code below. It still doesn’t work. So this module can’t be used to download binary files.

    var consumer = new OAuth('',
                null,
                consumer_key, consumer_secret, '1.0',
                null, 'HMAC-SHA1', 32, {encoding: "binary"});
    

    Solution: Use the request module to download the file. The code is as below.

    var oauth = {
        consumer_key: consumer_key
        , consumer_secret: consumer_secret
        , token: token
        , token_secret: token_secret
    };
    request.get({url:url, oauth:oauth, encoding: "binary"}, function(err, res, body){..});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With Node I am trying to collect user data from an LDAP server and
My node.js server is making a call to another server using the latest (0.4.8)
class Node { FooType Data; // I can save Data to file with extension
With node.js i can stream data to the client with its HTTP API. But
Regarding node.js, I'm using socket.io for real-time socket connection from the client application to
Node's HTTP module is not returning all the expected data from this URL: http://itradedata.co.za/pmchart/prices/GetPricesTRI.asp?Shortname=ACE&numprices=5
node.js doc says response.end([data], [encoding]) This method signals to the server that all of
In Node.js (using Express.js), when I call http.request like such: var options = {
using node.js, the net module for building a tcp server which can hande http
Backbone,Node : when i call fetch method, fetch is successful in server but when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.