Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of using the request library to upload a file to the Rev API
// 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:
var options = {
method: 'POST',
url: '',
{ '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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.