Tuesday, 23 May 2017

Translate a curl command to node.js

I have a curl command that postes a file to a rest-api. Now I'm trying to translate it to node.js but I'm really stuck. Do not know how to proceed, can anyone help me? The curl command works fine.

This is the curl command:

curl --user user:user -X POST -H "Content-Type: multipart/form-data" -F "data=@deploy.test.com-1.0.svaa" http://labb.local.com/rest-api/1/0/Labb/Addon%20Repository/testpacketering/moduleElementImport

And this is how far I have come:

var options = {
  host: "labb.local.com",
  path: encodeURI("http://labb.local.com/rest-api/1/0/Labb/Addon%20Repository/testpacketering/moduleElementImport"),
  port: 80,
  headers: {
    'Authorization': 'Basic ' + new Buffer("user" + ':' + "user").toString('base64'),
  },
  method: "POST",      
};

var request = http.request(options, function(response) {
response.setEncoding('utf8');

response.on("data", function(chunk){
    console.log(JSON.parse(chunk));
});
response.on("error", function(error) {
    console.log(error.message);
});

});

request.write("deploy.test.com-1.0.svaa");
request.end();

Getting the error: { type: 'resourceNotFound', description: 'Unable to find requested resource', message: 'Unable to process request, no JCR-node is specified' }



via Johan Nordli

No comments:

Post a Comment