-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Downloading ReleaseAsset zip File - NullReferenceException #854
Comments
There's definitely something unclear about this API - you can see a test I've written to download an asset here: In this case, I've done the download slightly different:
I think something weird is happening with the deserialization if you don't specify the appropriate |
Unsupported "application/octet-stream" {Octokit.ApiException: Unsupported 'Accept' header: ["application/octet-stream"]. Must accept 'application/json'. |
@kdolan well that's not great! Is this a repository I can test out (even privately?) - perhaps there's some edge case here I haven't seen before while working on this area... |
@shiftkey I just made a public repo for what I am trying to do. Basically an auto updater that downloads a zip file and then extracts it. In the repo I used the Nuget package but I've also used the project source with the same result. |
@kdolan thanks, I'll check it out |
@shiftkey After some more trouble shooting this appears to be an issue with the API/request. The error above is from the API not from this codebase. I verified this using postman. It would appear then that maybe the BrowserDownloadUrl is what needs to be used, however, whenever I try to download the file using postman I get a 404 (because it is a private repo) and token authentication does not appear to work for the browser download URL. |
I'm pretty sure that https://developer.github.com/v3/repos/releases/#get-a-single-release
Correct
Okay, this definitely sounds interesting. Do you see the |
var request = client.Release.GetAll("kdolan", "AutoUpdater");
var releases = await request;
var latest = releases[0];
var latestAsset = await client.Release.GetAllAssets("kdolan", "AutoUpdater", latest.Id);
//Download Release.zip here
var response = await client.Connection.Get<object>(new Uri(latestAsset[0].Url), new Dictionary<string, string>(), "application/octet-stream");
byte[] bytes = Encoding.ASCII.GetBytes(response.HttpResponse.Body.ToString()); ;
File.WriteAllBytes("Release.zip", bytes); This code is working for me; I was targeting the wrong API Endpoint. However, the actual writing of the zip file to disk does not seem to always work. The release for AutoUpdater just has a small text file in it and this code works fine, however, when I try other repos with larger Release Zips then the Zip file written is corrupt/incomplete. |
I figure out the reason for this It is because
Because it is binary type and we read as string in the I tried including that and it works. I am able to download the release and the file isn't corrupted. @shiftkey let me know if you want me to do PR on this? |
That'd be great! |
👍 |
This commit addressed the `BuildResponse` wasn't handling response `content-type` `application/octet-stream` for binary items.
This commit addressed the `BuildResponse` wasn't handling response `content-type` `application/octet-stream` for binary items.
I am trying to download a zip file that is an asset in a release.
I am getting a NullReferenceException in SimpleJson.cs in the DeserializeObject function at the line that reads obj = ConstructorCachetype; when I call client.Connection.Get.
If I have trying to get this to work without success for some time and have tried several different methods.
It is worth mentioning that I am trying to download from a private repo.
Potentially Related #792
The text was updated successfully, but these errors were encountered: