Tuesday 14 March 2017

node.js http request uploads binary data

Hi I am trying to use npm request-promise to make some HTTP call. This call should be able to upload a binary file. If it's done with cURL, the command looks like this:

curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip"
--data-binary @roads.zip
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/file.shp

Now I have to do this with node.js. If request-promise is not a proper tool, other similar modules also work. I have this code already:

const RequestPromise = require('request-promise');
RequestPromise({
    method: 'POST',
    uri: uriRoot + 'workspaces',
    auth: auth,
    // I don't know how identify data to upload here
    headers: {
        'content-type': 'application/zip'
    }
}).then((data) => reply(data)).catch((err) => reply(err));

Can anyone help me with it?



via zhangjinzhou

No comments:

Post a Comment