Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by mbellocchi on 16/05/2017.
- */
- var request = require('request');
- var fs = require('fs');
- var path = require('path');
- var crypto = require('crypto');
- var collectionPath = "../public/collections/56781ea712f7a8e414626754/";
- var folderMetadata = "3D/representativeMetadata/";
- var folderImgs = "3D/00001/";
- var img = "22264330492_8396e58b54_720_26734084@N04";
- // Set the headers
- var server_secret_key = "my_server_secret_key"
- const HTTPVerb = "POST";
- const ContentType = "multipart/form-data";
- const date = new Date();
- const RequestPath = "https://vws.vuforia.com/targets";
- var optionsOld = {
- url: RequestPath,
- method: 'POST',
- form: {
- "image": fs.createReadStream(path.join(__dirname, collectionPath + folderImgs + img + ".jpg")).toString('base64'),
- "name": img.split("@")[0],
- "width": 500.0,
- "application_metadata": fs.createReadStream(path.join(__dirname, collectionPath + folderMetadata + img.split("@")[0] + ".txt")).toString('base64')
- }
- }
- const ContentMD5 = crypto.createHash('md5').update(optionsOld.toString()).digest("hex");
- const StringToSign =
- HTTPVerb + "\n" +
- ContentMD5 + "\n" +
- ContentType + "\n" +
- date + "\n" +
- RequestPath;
- const hmac = crypto.createHmac('sha1', server_secret_key);
- hmac.update(StringToSign);
- //console.log(hmac.digest('hex'));
- //console.log(hmac.digest('base64'));
- var Signature = hmac.digest('base64');
- var AuthorizationValue = 'VWS '+ server_secret_key + ':' + Signature;
- var headers = {
- 'Content-Type': 'application/json',
- 'Authorization': AuthorizationValue
- }
- var options = {
- url: RequestPath,
- method: 'POST',
- headers: headers,
- form: {
- "image": fs.createReadStream(path.join(__dirname, collectionPath + folderImgs + img + ".jpg")).toString('base64'),
- "name": img.split("@")[0],
- "width": 500.0,
- "application_metadata": fs.createReadStream(path.join(__dirname, collectionPath + folderMetadata + img.split("@")[0] + ".txt")).toString('base64')
- }
- }
- console.log(AuthorizationValue);
- // Configure the request
- // Start the request
- request(options, function (error, response, body) {
- console.log(response.statusCode);
- if (!error && response.statusCode == 200) {
- // Print out the response body
- console.log(body);
- } else {
- console.log("Error", error);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement