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.
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.
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...
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:
@gmlewis @Jarlotee If no one else is looking at this, I'd be happy to take a look?
Sounds great, @aidenkeating - it is yours. Thank you.
@gmlewis @Jarlotee Apologies for the delay on this. I've created https://github.com/google/go-github/pull/1102 to address the enhancements suggested in https://github.com/google/go-github/issues/1097#issuecomment-454991132. 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?
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?
I think this can be closed, right?
Yes
Most helpful comment
@gmlewis @Jarlotee Apologies for the delay on this. I've created https://github.com/google/go-github/pull/1102 to address the enhancements suggested in https://github.com/google/go-github/issues/1097#issuecomment-454991132. 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.typesfiles are removed. It appearsgo-githubwill default toapplication/octet-streamif 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?