Created
November 12, 2018 21:19
-
-
Save ethanwillis/5582915ab249ba61abff6170d33aa30a to your computer and use it in GitHub Desktop.
Example of using the request library to upload a file to the Rev API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imports | |
var request = require("request"); | |
var fs = require('fs'); | |
var path = require("path"); | |
var mime = require('mime-types'); | |
let filepath = "/home/ethan/documents/myfile.mp4" | |
let filename = path.basename(filepath); | |
let client_api_key = "1234" | |
let client_user_key = "5678" | |
let filestream = fs.createReadStream(filepath); | |
let content_disposition_header = 'attachment; filename="' + filename + '"' | |
let content_type_header = mime.lookup(filepath); | |
let auth_header = "Rev " + client_api_key + ":" + client_user_key; | |
/** | |
In your content disposition header you will give rev the filename of the | |
file being uploaded. | |
In your content-type header you will need to give rev the mime-type | |
of the file you're uploading. | |
* For the list of all supported mime-types please view the documentation For | |
error code 10001 here: https://www.rev.com/api/inputspost | |
*/ | |
var options = { | |
method: 'POST', | |
url: 'https://rev.com/api/v1/inputs', | |
headers: | |
{ 'Content-Disposition': content_disposition_header, | |
'Content-Type': content_type_header, | |
'Authorization': auth_header | |
}, | |
encoding: null, | |
body: filestream | |
}; | |
request(options, function (error, response, body) { | |
if (error) throw new Error(error); | |
// The body will contain a URI that points to your media file hosted at Rev. | |
// You can use this URI to place new orders. | |
console.log(body); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment