Uploading a large file to OneDrive shared folder issue (createUploadSession error) - rest

Although Microsoft official documentation quite rich, I can't find any details of how exactly I should upload the large file to a shared folder (not to my drive).
I've followed the docs:
POST /drives/{driveId}/items/{itemId}/createUploadSession
{"Item":{"#microsoft.graph.conflictBehavior":"replace","name":"20200310-155252-700.jpg"}}
Where the itemId is the folder id I am trying to upload that file to.
However, it returns 400 Bad Request error Name from path does not match name from body message.
But the request path provided in docs doesn't expect passing the file name at all!
I kind of suspecting that the itemId should be an existing item on the drive (not even inside the folder), rather than a folder id to create that file in, but a) I am not sure about that and b) how is it possible to have an empty file without any content before having that upload complete (again, if I am right about b)).
Am I at least following a right direction? Thanks!

This is because poorly updated OneDrive Api official documentation Microsoft has.
A correct url must be as follows:
$"{baseUrl}/drives/{drive}/items/{itemId}:/{fileName}:/createUploadSession"

Related

How do you call the Artifacts - Get File endpoint?

This is what the documentation says:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=6.0
But where do I get the fileId and the fileName (I assume fileName means that I also need to know the path)?
(I already know how to download the artifact as a zip but that's not what I want to do)
This is related, but I want to use documented API where I don't have to generate a full scope PAT: In Azure DevOps, is it possible to enumerate children pipeline build artifacts recursively with API?
Thanks
I found this post as a workaround for the issue, couldn't find any recent answers
https://developercommunity.visualstudio.com/t/download-single-file-from-artifact-via-api/1093589
Current working workaround (as of date of posting):
1. get artifact using https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get artifact?view=azure-devops-rest-5.1
2. Get Resource -> DownloadUrl string
3. Replace entire query from "?format=zip" to "?format=file&subPath={path to the item including the root}"
4. Use URL to download file
Note: To the url i had to add "%2F" before the file name that's how the actual url to the file looks like.
Update:
I asked on the developercommunity and their answer was this:
I have reviewed the ticket you mentioned, and you don’t need to get the fileID, but get the resource.data by using this API :
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get artifact?view=azure-devops-rest-5.1
Then, use this API where resource.data is from the previous call (remove # prefix):
GET https://dev.azure.com/{organization}/{project}/_apis/resources/Containers/{resource.data}?itemPath={path to the item including the root}
A way to verify the URL you are constructing is correct, go to the Artifacts page that is linked off the Build Summary page and you will see the option to copy the download URL for an individual file there. The URL should be the same.
https://developercommunity.visualstudio.com/t/Download-single-file-from-drop-artifacts/10000465

Access file content within an Azure Dev Ops/VSTS artifact using REST API

I am looking to get the contents of a file I pushed as an artifact to Azure DevOps
I was able to get a json response with a URL to the artifact zip by using this API
https://dev.azure.com/uifabric/cd9e4e13-b8db-429a-9c21-499bf1c98639/_apis/build/builds/8838/artifacts?artifactName=drop&api-version=5.0
However, what I really want is the contents of a file called bundlesizes.json within this zip.
I did come across the Get File API here which mentions an API as follows
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=5.0
I tried replacing it as follows
https://dev.azure.com/uifabric/fabricpublic/_apis/build/builds/8838/artifacts?artifactName=drop&fileId=bundlesizes.json&fileName=bundlesizes.json&api-version=5.0
However, I get this error
I think what I am missing is the fileId field, where I am not aware what needs to go in. The documentation says fileId is the The primary key for the file. However, I don't know where I can find it.
Microsoft doesn't have complete documentation on how to get FileID.
You can take a different approach and download the file using below API. You can get the ContainerID through GET build details.
https://collectionurl/tfs/defaultcollection/_apis/resources/Containers/${containerid}?itempath=drop

Relative Link to Repo's Root from Markdown file

I need to have a relative link to root of my repo from markdown file
(I need it working for any forks)
So it looks like the only way it's to provide a link to some file in the root:
the [Root](/README.md)
or
the [Root](../README.md)
(if it's located at /doc/README.md for instance)
At the same time I can refer to any folder without referring to a file
the [Doc](/doc)
But if I try to put a link to the root folder:
the [real root](/)
the [real root](../)
I'll have a link such
https://github.com/UserName/RepoName/blob/master
which unlike the
https://github.com/UserName/RepoName/blob/master/doc
refers to 404
So if I don't want to refer to README.md in the root (I could havn't it at all)
Is there any way to have such a link?
After some research I've found this solution:
[the real relative root of any fork](/../../)
It always points to the default branch. For me it's Ok, so it's up to you
PS
With such a trick you can also access the following abilities:
[test](/../../tree/test) - link to another branch
[doc/readme.md](/../../edit/master/doc/readme.md) - open in editor
[doc/readme.md](/../../delete/master/doc/readme.md) - ask to delete file
[doc/readme.md](/../../commits/master/doc/readme.md) - history
[doc/readme.md](/../../blame/master/doc/readme.md) - blame mode
[doc/readme.md](/../../raw/master/doc/readme.md) - raw mode (will redirect)
[doc/](/../../new/master/doc/) - ask to create new file
[doc/](/../../upload/master/doc/) - ask to upload file
[find](/../../find/test) - find file
You can either link directly to the file (../README.md), or simply use a full absolute URL to link directly to the repo root: https://github.com/UserName/RepoName
Using relative links doesn't work so well on GitHub. Notice the difference between the following two URLs:
https://github.com/UserName/RepoName/tree/master/somedir
https://github.com/UserName/RepoName/blob/master/somedir/somefile
Notice that the first points to a directory and the second points to a file. Yet, after the "RepoName" we have either one of tree (for a directory) or blob for a file. Therefore relative links between the two won't work properly. On GitHub, you can't use relative links to link between a file and a directory. However, you can link between two files (as both URLs contain blob). Therefore, if you wanted to link from somefile back to README.md in the root, you could do:
[README](../README.md)
That would give you the URL:
https://github.com/UserName/RepoName/blob/master/somedir/../README.md
which would get normalized to
https://github.com/UserName/RepoName/blob/master/README.md
However, if you just want to point to the root of your Repo (or any other dir), then it is probably best to use a full URL. After all, if someone has downloaded your repo and is viewing the source locally, the relative URL to the Repo root will be different than when viewing the file on GitHub. In that case, you probably want to point them to GitHub anyway. Therefore, you should use:
[root](https://github.com/UserName/RepoName)
Another advantage of that is that if your documentation ever gets published elsewhere (perhaps a documentation hosting service), the link will still point to the GitHub repo, not some random page on the hosting service. After all, the README at your project root is not likely to get included with the contents of the docs/ dir on said hosting service.
Perhaps it would help to understand how GitHub's URL scheme presumably works. I say "presumably" as I have no inside knowledge, just a general understanding of how these types of systems are generally designed.
GitHub is not serving flat files. Rather their server is taking the URL apart, and uses the various pieces to return the proper response. The URL structure looks something like this:
https://github.com/<username>/<repository name>/<resource type>/<branch>/<resource path>
The username, repository name, resource type, and branch are rather arbitrary and just ways to GitHub to ensure they are pulling information from the correct location.
The resource type matters as they are likely not pulling files from a working tree. Rather they are pulling the files/directory listings directly from the Repo itself through a lower level. In that case, obtaining a file is very different than obtaining a directory listing and requires a different code path. Therefore, you can't request a blob (file) with aresource path that points to a tree (directory) or visa versa. The server gets confused and returns an error.
The point is that GitHub's server works on a slightly different set of rules. You can use relative URLs to move around within the resource path part of the URL, but once you change the resource type in the resource path part of the URL, then GitHub's entire scheme is broken if you don't also change the resource type in the URL. However, browsers (or HTML or Markdown) have no knowledge about that and relative URLs don't compensate for that. Therefore, you can't reliably use relative URLs to move around within a GitHub repo unless you understand all of the subtleties. Sometimes its just better to use absolute links.

Download / upload file using the Add-On SDK

I am currently trying to download a small binary file from the web, in order to upload that to another website, both using the API.
Previous versions seemed to have the "file" API module for such purposes, but I can't see anything similar as of the latest (1.14).
The file to be downloaded would be saved in some form of cache (browser cache, preferably), its path stored somewhere, to be then uploaded to another URL via POST.
How would I go about it, when the process should happen completely in the background?
I checked out the how to download a file page, but can't figure out where to download.
Is there a variable URI for the "Downloads" directory, and does a regular Add-On has write privileges in it?.
This is important, because the add-on must be able to function properly on various platforms.
You can use the pref, browser.download.lastDir, which should work for windows/mac as it will be saved in the OS format. However the pref may not always be set if the person has never downloaded anything before. In that case you'll have to build the directory yourself.
var dir = require("sdk/preferences/service").get('browser.download.lastDir');
To build the directory yourself you're going to have to go a little deeper. Check this article on MDN about File I/O which has examples. The DfltDwnld key should give you the directory you want.
Your add-on will have write permissions to everything Firefox has write permission to.

Downloaded ppt file seems to be corrupted

Recently I've integrated Google Drive with my iOS application. Everything works fine but .ppt files. Normally if a file is a Drive file I use downloadURL to download it. If the file belongs to Google Docs I use one of the exportLinks (exactly the same as Alain described it here).
However all .ppt files (with "mimeType": "application/vnd.google-apps.presentation") which come from Google Docs are corrupted after being downloaded (I use an export link with exportFormat=pptx). The same file downloaded via web browser works fine.
I use ASIHTTPRequest lib for downloading files (which also can be the reason of corrupted .ppt?).
Any ideas why only ppt files cause problems?
I can already tell you that the lib you're using isn't the cause:I'm not using it but I've the same problem: it seems that there the code received isn't 200 (if ($httpRequest->getResponseHttpCode() == 200)) as it shows me a specific error message I've asked to return in case of. Also, when I'm trying to download a presentation in PDF or txt, it shows the same error.
It's not really an answer but I'm trying to understand also why only presentations are causing problems.
EDIT: the code received is 302. If it can help...
EDIT 2: After trying, I noticed that the first parameter is the file id and the second the export format:
https://docs.google.com/feeds/download/presentations/Export?docId=filedid&exportFormat=pptx
But in the 302 code, I have this location:
https://docs.google.com/feeds/download/presentations/Export?exportFormat=pptx&id=fileid
Not only the two parameters aren't in the same order but the name is id and not docid
When I take this URL, put it as the export link and then try to copy the file, it's working. I get a 200 response and the inside of the file.
I hope it helps.