WOPI : File content is not displaying in DOC Viewer - node.js

I have implemented WOPI in my Vue.js app and implemented a GET API in Node.js to return the file content, still iam unable to see the content in DOC viewer in front-end and there are no errors even, attached screenshot of UI here:
UI DOC Viewer
The following is the action URL sample that i tried.
https://ffc-word-view.officeapps.live.com/wv/wordviewerframe.aspx?wopisrc=https://app.maindomain.com/file/v1/wopi/files/1269474
The following is the API Code which i wrote to read a file from Azure Blob storage and to return the file content:
var request = require('request');
request.get('<FILE_BLOB_URL>',{responseType: 'arraybuffer'}, function (error, response, body) {
if (!error && response.statusCode == 200) {
let json = JSON.stringify(body);
let bufferOriginal = Buffer.from(JSON.parse(json));
res.status(200).send(bufferOriginal)
}else{
console.log('WOPI Files Content Read Err is:');
console.log(error);
}
});
Can anyone suggest me the that the way that iam returning the file content is correct or not?

I have implemented '/wopi/files/:FID' API only for time-being, to get this working do i need to implement other endpoints also which were proposed in CSPP document?
To get the View mode working, you need at least:
CheckFileInfo
GetFile
To support the Edit mode, you need:
PutFile
*Lock - all locking operations

Related

How to open web brower by using AWS post lambda

I have written the piece of code below:
static async postSearchResult(httpContext: HttpContext, injector: Injector) {
const log = injector.get(Log);
const service = injector.get(Service);
try {
let result = await service.redirectToUI(JSON.parse(httpContext.getRequestBody()));
httpContext.ok(result, 200, {'Content-Type': 'application/json'});
} catch (e) {
httpContext.fail(e, 500);
}
}
protected redirectToUI(response: any) {
// If any post api call happened then it should open web browser and pass some field as query parameter
window.open("https://www.google.com?abc=response.abc");
return response ? response : "failed";
}
Here I am getting the following error :
Execution failed ReferenceError: Window is not defined
What am I doing wrong?
What you are trying to accomplish doesn't make much of a sense. Lambda is a back-end service. To open new browser window, you need to use front-end JavaScript, not back-end Node (on the back-end, you have no access to the front-end window object).
If you want to open a new browser window as a reaction to some back-end response, then you can send some indicator in the HTTP response (i.e shouldOpenNewWindow: true as a part of the response object), parse that response on the front-end and it the indicator is present, then you can issue window.open command. But it has to be done on front-end.

How to get data from api on html view using node js?

var Request = require("request");
Request.get("https://www.yonline.com", (error, response, body) => {
if(error) {
return console.dir(error);
}
document.getElementById('msg').innerHTML=JSON.parse(body)
console.dir(JSON.parse(body));
});
I tried this code, but it is only giving data on the command line. i want it to give data on the intended textfield.
NodeJS is server side script you can't access HTML element like this.
You need to do it on html javascript side.

How to retrieve data from API using nodejs coffeescript

I have an API and i want to retrieve API data.I am using nodeJS and
coffeescript.How can i write nodejs script using coffeescript.Here is
my API and want to retrieve data from that API.Please help me.
http://apiprod.yourstory.com/v1/site/YOURSTORY/articles/
Please try to install request package using npm and use below code :
var request = require('request');
//Lets try to make a HTTP GET request to modulus.io's website.
request('http://www.modulus.io', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body); // Show the HTML for the Modulus homepage.
}
});
Below link explains in more detail :
http://blog.modulus.io/node.js-tutorial-how-to-use-request-module

596 Service not found while using ESPN API

I am using this API to consume a ESPN API:
http://api.espn.com/v1/now?apikey=d4skkma8kt2ac8tqbusz38w6
In Node.js, using node-curl library, my snippet looks like this:
var Curl = require('node-curl/lib/Curl')
curl.setopt('URL', url);
curl.setopt('CONNECTTIMEOUT', 2);
curl.on('data', function(chunk) {
console.log(chunk);
});
But everytime when I run this code I keep on getting response as:
<h1>596 Service Not Found</h1>
Strange is, same URL if I hit from the browser I get the correct response so URL is not invalid. This happens only if I try to call from Node.js. Can anyone guide me how to resolve this error? I tried encoding/decoding url, still I get same response.
Also basically I am avoiding any vendor specific libraries as much as possible, since we should have generic api calling framework
You could use request, which is a very popular module. Here's an example of how you could do it:
var request = require('request');
var url = 'http://api.espn.com/v1/now?apikey=d4skkma8kt2ac8tqbusz38w6';
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(JSON.parse(body));
}
});

Reddit API only returning one post

I am trying to get all of the links in a subreddit using the API, but it is only returning one url. Here is the code I have:
var request = require('request');
webpage = 'http://www.reddit.com/r/AmazonUnder5/top.json?limit=100';
//login
request.post('http://www.reddit.com/api/login',{form:{api_type:'json', passwd:'password', rem:true, user:'username'}});
//get urls
request({uri : webpage, json:true, headers:{useragent: 'mybot v. 0.0.1'}}, function(error, response, body) {
if(!error && response.statusCode == 200) {
for(var key in body.data.children) {
var url = body.data.children[key].data.url;
console.log(url);
}
}
});
When I visit the json link in my browser, it returns all 100 posts.
Thats because only 1 exists in the top
http://www.reddit.com/r/AmazonUnder5/top
You could use hot instead
http://www.reddit.com/r/AmazonUnder5/hot.json
Also, you don't need to log in to do public get requests
Edit: You are getting so few results because you are not logged in properly
When logging in, use the
"op" => "login"
Parameter and test what cookies and data is returned.
I also recommend using the ssl login url since that works for me
https://ssl.reddit.com/api/login/

Resources