Download file from webservice - rest

I want to download file on clik of image. We have rest api which download the zip file when called. I am.able to get desired output when call that api from browser and rest console. However when I try to call it from ajax call it gives cross domain origine present method not allowed error.
Any help will be appreciated.

It seems like you overcomplicated it. If you can test your API from your browser, I assume it's a simple HTTP GET call so you don't need fancy stuff like Ajax: just open the link, your browser know how to download a file.
Opening in the same window: location.href = 'http://my_server.com/my_api/downloadFile/54ef654zeze4'
Opening in a new window: parent.open('http://my_server.com/my_api/downloadFile/54ef654zeze4')

Related

"Client Error" message when trying to implement an Rest API View

I'm creating an API with Drupal to serve a angular application. The problem is, when I create the view with Rest export and try to access it (via browser or postman), it gaves me an "Client error" message (and nothing more).
I'm using drupal-8.7.6, running with PHP7.3, mysql and apache 2. But I've tried at nginx also and the error appeared again.
To reproduce it, just add some contents, enable the Restful web services, jsonm hal and create a view that exports rest data.
I expect to access the information via GET request (using browser, postman or any other way)
Go to your View
Go to Format
Click on Settings beside Serializer
Finally check Json option and save.
You are done :)
find out what was happening
I was not specificating the format of output, so Drupal was searching for an html to serve. To workaround this, just add to url: ?_format=json, for example, if my view route is "/articles", it will be: http://drupal.dev/articles?_format=json
Go to the rest exports view, click on format setting and click accepted request format to json.

Postman can't seem to find my backend api and I can't find out why

I've written a backend api in .net and I would like to test my methods but when I open postman and try my different methods, it never works:
Could not get any response
There was an error connecting to xxx/api/videos
The strange thing is that if I click the embedded link, it takes me to the right page of my api and shows me the json that I expect (now I use this url as an example, I want to test a post method and I con't view this one in the browser). If any of you know what to do, let me know.
click here in settings, one pop up window will get open. There we have switcher to make SSL verification certificate. Switch to (Off).

Google youtube api sample: Where to paste authentication code?

Trying to run the sample code here: https://github.com/google/google-api-nodejs-client/blob/master/samples/youtube/playlist.js
It opens the browser after node playlist, and after allowing all the permissions, displays the screen below.
Pasting the code back to the console does nothing.
Not sure how to proceed from there.
Well in the comments they wrote:
// Open an http server to accept the oauth callback. In this
// simple example, the only request to our webserver is to
// /oauth2callback?code=<code>
Opened a new window and paste the code in http://localhost:3000/oauth2callback?code=<code>. The instruction could be improved imo.

How to make REST call to MS Graph/OneDrive method with OAuth2

I am trying to use the OneDrive API and I have successfully registered my app through their Application Registration Portal. I can call successfully call the Javascript FilePicker SDK to upload and download files
That demonstrates that I have my app registered properly and the proper app/client-id's.
Now I'd like to use the REST services to upload and download files but I'm not sure how to send authentication and I don't know how to make the call to the proper URL.
My first question is: How can I use the token I created in the reg service to make a REST call?
My second question is: What syntax should I use to upload a file? I don't know where to put the URL to make the call.
The PUT documentation for their upload is found here
<script type="text/javascript">
function launchSaveToOneDrive(){
var xhttp = new XMLHttpRequest();
//Authorization: bearer {token}
xhttp.open("PUT", "/drive/items/{parent-id}:/{filename}:/content", false);
xmlhttp.setRequestHeader("Authorization", "Bearer-xxxxxxxxxxxxxxxxxxx");
xhttp.setRequestHeader("Content-type", "text/plain");
xhttp.send();
var response = JSON.parse(xhttp.responseText);
}
</script>
One option is to use the Microsoft Graph JavaScript SDK that can help with REST calls including uploading files to OneDrive through the MS Graph. The library works with client side JavaScript and Node for JavaScript server apps.
Check the Browser folder under samples to see how to use the SDK in a client app. Uploading a file would look something like this (see that link for the full code):
// file variable is from the contents of an input field for example
var file = document.querySelector('input[type=file]').files[0];
// after user selects a file from the file picker
client
.api('/me/drive/root/children/Book.xlsx/content')
.put(file, (error, response) => {
// supports callbacks and promises
});

Codeigniter Facebook app POST method AND query_string

I have a toy facebook app I'm playing with so I can understand how it all works. It's fine if you go the the app like this: http://apps.facebook.com/pushup-challenge/ (and connect it). But if you then go to it from your facebook page, FB uses the URL http://apps.facebook.com/pushup-challenge/?ref=bookmarks.
In my log file, I see that FB is POSTing the data and including the /?ref=bookmarks to it's call to my codeigniter system. This is causing it to either say "invalid URI parameters" or give me a 404, depending on if I've edited the system/core/URI.php file to add rawurlencode() to a particular call.
I've tried using mod_rewrite to get rid of the query_string, too, but since it's POSTing, it doesn't appear to be working (though I'm not exactly sure why).
Has anyone else run into this? How did you fix it?
Thanks in advance,
Hans
try $config['uri_protocol'] = “PATH_INFO”; and set enable_query_strings = TRUE
or
set
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?=';
in config.php
Because it isn't calling your file by name (just ?ref=bookmarks) the server runs thru the standard default files: index.htm, index.html, index.asp. Because you need to accept a POST, you need a server that allows POSTs to htm & html if you choose to use those. Index.asp will accept POSTs on most servers, and that works for me.
SOLUTION: Add a file (index.asp), that calls the real app that you named in the App settings.