3

I want to to bulk translocation and for that I uploaded the.csv file, its worked for me if I am using curl command but when I used its on node code its showing me error "file not uploaded"

Regarding to curl I am using that code which is working for me :-

curl -F  'data=@/var/www/html/achupload.csv' https://sandbox.usaepay.com/api/v2/bulk_transactions  -H "Authorization: Basic X3llMVI3Mk9PdzFHOXBqcW1GaVp2NHJINjRc="

and this is my node code which are showing me error message :-

    var request = require('request');

    var headers = {
          'Authorization': 'Basic X3llMVI3Mk9PdzFHOXBqcW1GaVp2NHJINjRc='
    };

    var dataString = '@/var/www/html/achupload.csv';

    var options = {
        url: 'url',
        method: 'POST',
        headers: headers,
        data: dataString
    };

    console.log("options====",options);

    function callback(error, response, body) {
        if (!error && response.statusCode == 200) {
        console.log(body);
        }
        else{
          console.log("notttttttttttt================",response.body);
        }
    }

    request(options, callback);
1
  • Because dataString is a string, not your csv file content. Commented Sep 11, 2019 at 7:49

1 Answer 1

1

How about this modification?

Modification points:

  • File content is retrieved with fs.createReadStream().
  • The file is sent as formData.

Modified script:

From:
var request = require('request');

var headers = {
      'Authorization': 'Basic ###'
};

var dataString = '@/var/www/html/achupload.csv';

var options = {
    url: 'url',
    method: 'POST',
    headers: headers,
    data: dataString
};
To:
var fs = require('fs');  // Added
var request = require('request');

var headers = {
      'Authorization': 'Basic ###'
};

var dataString = {data: fs.createReadStream('/var/www/html/achupload.csv')};  // Modified

var options = {
    url: 'url',
    method: 'POST',
    headers: headers,
    formData: dataString  // Modified
};

Note:

  • In this modified script, 'Authorization': 'Basic ###' was used. Please be careful this. When you use this, please replace ### to yours.

References:

If this didn't resolve your issue, I apologize.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, you make my day :)
@Mangita Welcome. I'm glad your issue was resolved. Thank you, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.