Created
November 12, 2018 23:45
-
-
Save ethanwillis/1cb1e549628218542c0a13032122b010 to your computer and use it in GitHub Desktop.
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/Downloads/sample_iTunes.mov" | |
let filename = path.basename(filepath); | |
let client_api_key = "" | |
let client_user_key = "" | |
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://api-sandbox.rev.com/api/v1/inputs', | |
headers: | |
{ 'Content-Disposition': content_disposition_header, | |
'Content-Type': content_type_header, | |
'Authorization': auth_header | |
}, | |
body: filestream | |
}; | |
request(options, function (error, response, body) { | |
if (error) throw new Error(error); | |
// The location header will contain the URI for your uploaded file on Rev's servers. | |
console.log(response.body) | |
console.log(response.headers); | |
console.log(response.statusCode); | |
console.log("File URI on rev's servers: " + response.headers.location); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment