data-Binary in request nodejs

Viewed 2249

I'm trying to upload a file to dropbox throug nodeJS. This CURL request works.

curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer myToken" \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @fileName

I don't know how to translate it into javascript code. Here's what I've accomplished so far:

    var request = require('request')
    var headers = {
        "Authorization": "Bearer " + dropboxToken,
        "Dropbox-API-Arg": {
                            "path": "/"+fileName, //nome sul drive
                            "mode": "add",
                            "autorename": true,
                            "mute": false
                            },
        "Content-Type": "application/octet-stream"
    }
    var options = {
        url: 'https://content.dropboxapi.com/2/files/upload',
        method: 'POST',
        headers: headers,
    }
    request(options, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body)
        }
    });

How do I include the data-binary option in this request in order to select the file to upload?

Thanks.

2 Answers
Related