We have to access several OneDrive files using Microsoft graph API. This works well until we met some file whose name ends with .svc (they are regular files).
We have a request that looks like:
https://graph.microsoft.com/v1.0/users/account#xxx.onmicrosoft.com/drive/root:/file.svc
And it fails with a 400 Bad request (all other requests succeed).
We have tried the following, without success:
Escape the dot . with %2E
I’ve seen that the .svc extension was stripped, so doubled it, the file name becomes file.svc.svc
How to encode a file name with a .svc extension so graph API accepts it? (There is a way for sure, since we managed to upload such a file)
To access file content itself, the URI had to be https://graph.microsoft.com/v1.0/users/account#xxx.onmicrosoft.com/drive/root:/file.svc:/content (the :/content at the end does the trick, because it is semantically correct).
Related
My app is using client_credentials, and is successfully consuming the Graph API on most calls.
However, I have been attempting to get images from a sharepoint folder by path and filename:
https://graph.microsoft.com/v1.0/drive/root:/sites/folder1/folder2/folder3/folder4/photo.jpg
The appropriate headers are being set (authorization and accept).
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + session["access_token"]);
httpClient.DefaultRequestHeaders.Add("accept", "application/json; odata.metadata=minimal");
The request returns a 404 - Not found response.
When I navigate to our sharepoint site, I can see the image fine so I can only assume the file path is correct:
https://ourcompany.sharepoint.com/sites/folder1/folder2/folder3/folder4/photo.jpg
Apologies, but I am new to Graph API and couldn't find anything referencing this in the documentation:
https://learn.microsoft.com/en-us/graph/api/resources/onedrive?view=graph-rest-1.0
Path
/me/drive/root:/path/to/file
Resource
Access a DriveItem by path relative to the user's OneDrive root folder.
Are there special permissions needed for this? I found something suggesting permissions might be required in azure portal but this is to do with azure active directory and I'm not sure if it will affect the graph API, as it was working OK, reading drives and drive items in sharepoint (by drive id and drive item id, not by file path).
EDIT: Went into azure portal, added Graph API permissions to application:
Site: ReadAll
Directory: ReadAll
File: ReadAll
No change so far.
A site contains the drive so you're referencing things in the wrong order. To get a DriveItem from a site's drive, you want this:
/sites/{siteId}/drive/root:/folder1/folder2/folder3/folder4/photo.jpg
If you're looking to download the DriveItem instead of just retrieving the metadata, you'll want this:
/sites/{siteId}/drive/root:/folder1/folder2/folder3/folder4/photo.jpg:/content
I'm trying to upload a large file through Zuul.
Basically I have the applications set up like this:
UI: this is where the Zuul Gateway is located
Backend: this is where the file must finally arrive.
I used the functionality described here so everything works fine if I used "Transfer-Encoding: chunked". However, this can only be set via curl. I haven't found any way to set this header in the browser (the header is rejected with the error message in the console "Refused to set unsafe header ..".
Any idea how to instruct the header to set this header ?
It seems that actually there are 2 possible ways to upload large files via zuul:
By using "Transfer-Encoding: chunked" in header (but this cannot be used in a browser, as mentioned in the initial question, because this header is considered unsafe)
By bypassing the DispatcherServlet servlet used by zuul (using the /zuul path in front of the usual path that I was using).
I found the documentation not very clear in this aspect (that you can use either of the 2 options). In my case, considering that the file was being uploaded via Angular Js (hence in the browser), I had to use the second approach.
I'm trying to get Wopi host implementation in Ruby on Rails application.
My domain is whitelisted under CSPP. Trying to get the file contents in iframe, but I just see "Word Online" and a loading gif, I return binary file contents of docx as response to ..wopi/files/:id/contents. I don't get any calls hitting my host server.
Sample wopi_src_url: https://word-view.officeapps-df.live.com/wv/wordviewerframe.aspx?ui=1033&rs=1033&dchat=false&IsLicensedUser=0&WOPISrc=https://sgdevwopi.test-wopi.sycamoreinformatics.com/wopi/files/31/contents?access_token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2&access_token_ttl=160000000
Able to get the Wopi validation page in Iframe using .wopitest file. How should I proceed further? Or what am I missing? Please help.
Note: I'm using ngrok to make my local app server visible publicly with whitelisted domain.
I see to problems with your URL. You must ensure that
the URL is of the form http://server/<...>/wopi/files/(file_id) (so drop the /contents part - WOPI client will call the /contents endpoint automatically when necessary)
the WOPISrc parameter value is encoded to a URL-safe string
More info here and here.
I can easily create a URL File through the O365 OneDrive web UI. Right click > New > Link. Enter the URL and save. The new item appears in the UI and when clicked, it will take you directly to the new URL, let's say it's www.google.com.
I'm attempting to duplicate this with the Graph API.
GET /me/drive/items/{folderId}/children
with:
{ name:'www.google.com.url',
file:{}
}
It creates what appears to be a link in the OneDrive UI but when clicked, it will not take you to the URL, it attempts to download a file. I've tried creating it with and without the .url suffix. The API looks pretty limited and there aren't many options to pass. I've also tried the beta API, same issue.
Links are actually a file with a special syntax similar to an INI file. From the sample you included here, it looks like you're creating an empty (0 byte) file named "www.google.com.url". Since the empty file doesn't match the format expected for a .URL file, OneDrive doesn't know what to do with it and just downloads the file.
To create a link programmatically, you would need to make a request like this:
PUT https://graph.microsoft.com/v1.0/me/drive/root/children/ShortcutToBing.url/content
Content-Type: text/plain
[InternetShortcut]
URL=https://www.bing.com
This will create a file named ShortcutToBing.url, and fill the contents of the file with the text below the request, which is the contents of a .URL file, pointing to www.bing.com.
Does anyone know if Brackets Shell uses any URI except the file://...index.html format? I want to point a web service back to the shell and need to provide a valid URI with the URL. The problem is that I noticed that the URL for the index file uses basic system paths and this can change per system or user configuration.
Any way around this little problem?
Edit:
I am trying to access the Instagram API through brackets shell. In order to gain an access token to the OAuth method they use I need to redirect the user to the Instagram Login page to log in then grant access and then Instagram will redirect them back to me based on the call back or redirect url provided from me. If it was as simple as providing just the URL when the call was made I would be fine however to get a client key (which is also needed to access the api) I need to provide the correct call back URL once the key is made and since the shell seems to have no custom file path it's almost impossible to predict the file path based on each users setup on their own pc's. I hope this made sense :)
I searched the source of the brackets-shell, but couldn’t find the startup path. A quick workaround would be adding a meta-refresh to your index.html which redirects to the corresponding URL of your web service.
For example:
<meta http-equiv="refresh" content="0; url=http://example.com">
If you don’t want to select your index.html each time you start your custom shell, you should place your index.html at
Mac: Brackets.app/Contents/dev/src/index.html or Brackets.app/Contents/www/index.html
Win: dev/src/index.html or www/index.html (these folders must be in the same folder as Brackets.exe)
Linux: dev/src/index.html or www/index.html (these folders must be in the same folder as the Brackets executable)
You can get the current location through javascript using
document.location.href
this will return a string like
"file:///C:/Program%20Files%20(x86)/YourApp/www/index.html"
which you might try sending to Instagram. I'm not sure if they will accept file URI's though.