Skip to content
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

502 Error Uploading Release Assets - Missing Mime Types #1097

Closed
Jarlotee opened this issue Jan 14, 2019 · 9 comments
Closed

502 Error Uploading Release Assets - Missing Mime Types #1097

Jarlotee opened this issue Jan 14, 2019 · 9 comments

Comments

@Jarlotee
Copy link

If the host is missing mime types files (see Go Mime Documentation) the upload of assets will fail with a 502 Error creating policy []

The call to UploadReleaseAsset should return an error if no compatible mime type is found, because the error thrown by github is cryptic and unhelpful.

Additionally it might be helpful to allow the user to specify the mime type.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 16, 2019

By "the host" do you mean GitHub?
Can you please provide a simple test case that exhibits the problem, and an example failing MIME type?

For others tuning in, we are talking about:
https://developer.github.com/v3/repos/releases/#upload-a-release-asset

and this method:
https://github.com/google/go-github/blob/master/github/repos_releases.go#L339-L370

I notice that on line 358 we have:

mediaType := mime.TypeByExtension(filepath.Ext(file.Name()))

and I agree that it might be nice to be able to override the mediaType by adding a new MediaType field to the UploadOptions struct.

Your test case could help someone address this issue.

Thanks for reporting this, @Jarlotee! This sounds like a good issue to address.

@Jarlotee
Copy link
Author

Jarlotee commented Jan 16, 2019

The host meaning the server that is running your api.

For example if I build from alpine linux I would not have a mime.types file available...

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 17, 2019

Ah! I think I get it now. I was confused because this is technically a "client library" to the GitHub API.

OK, so your "host" is a server running your own API that then uploads files (as a client) with various MIME types to the GitHub API. Gotcha. Please correct me if I'm wrong.

So yes, this would be a good enhancement:

  • enable the ability for this client library to specify the MIME type, and
  • improve the error messages when the GitHub API rejects an upload due to an invalid MIME type.

@aidenkeating
Copy link
Contributor

@gmlewis @Jarlotee If no one else is looking at this, I'd be happy to take a look?

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 21, 2019

Sounds great, @aidenkeating - it is yours. Thank you.

@aidenkeating
Copy link
Contributor

@gmlewis @Jarlotee Apologies for the delay on this. I've created #1102 to address the enhancements suggested in #1097 (comment). Mainly just allowing MediaType to be specified in UploadOptions.

I could not reproduce the GitHub API rejecting the upload due to an invalid MIME type, even after ensuring all mime.types files are removed. It appears go-github will default to application/octet-stream if no media type is provided when creating the upload request. That seems to work fine. (see https://github.com/google/go-github/blob/master/github/github.go#L361).

Wondering if the error/fix fix was coincidental and it was an issue on the GitHub side? Might be missing something in reproducing though?

From reading https://developer.github.com/v3/repos/releases/#response-for-upstream-failure a 502 isn't guaranteed to be a MIME type issue, I'm not sure whether it makes sense to provide an improved/more specific error message unless the cause is guaranteed. wdyt?

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 23, 2019

Thank you for digging into this and reporting back, @aidenkeating! It is greatly appreciated!

@Jarlotee - can you please provide a simple test case with details on how to reproduce the problem?

@philips
Copy link

philips commented Jun 21, 2019

I think this can be closed, right?

@Jarlotee
Copy link
Author

Yes

n1lesh pushed a commit to n1lesh/go-github that referenced this issue Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants