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

net/http: DetectContextType: recognize svg file as image/svg+xml #15888

Closed
tnclong opened this issue May 30, 2016 · 5 comments

Comments

Projects
None yet
6 participants
@tnclong
Copy link

commented May 30, 2016

What version of Go are you using (go version)?

go version go1.6.2 darwin/amd64

What did you do?
I want to upload svg file to aws s3. I use http.DetectContentType(buffer) to get the content type.
I really want the http.DetectContentType(buffer); back image/svg+xml replace text/xml; charset=utf-8. Because the browser don't show the svg images when <img src="s3/a-svg-file.svg"> if you give browser ContentType: text/xml; charset=utf-8.
I think it's more suit for web develop.

What did you expect to see?
image/svg+xml

If the function out of http.DetectContentType(buffer) scope or you have suggestions for me. Welcome to reply.
Thank you very much and sorry for my bad English.

@tnclong tnclong changed the title net/http/sniff: pase svg file to text/xml; charset=utf-8 net/http/sniff: pase svg file to image/svg+xml May 30, 2016

@tnclong

This comment has been minimized.

Copy link
Author

commented May 30, 2016

I added extra logic to my code.
Get ContentType from Extension first.

fileType := mime.TypeByExtension(path.Ext(filePath))
if fileType == "" {
    fileType = http.DetectContentType(buffer)
}

It fix my problem, although don't feel nice.

If you feel don't need the feature. Please close this.
Sorry for the noise.

@ianlancetaylor ianlancetaylor changed the title net/http/sniff: pase svg file to image/svg+xml net/http: DetectContextType: recognize svg file as image/svg+xml May 30, 2016

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone May 30, 2016

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 30, 2016

Marking as 1.8 to decide whether or not to do it in 1.8. It would help to know whether other systems, such as the file command, recognize SVG files, and how they do it.

@miguel-guedes

This comment has been minimized.

Copy link

commented Aug 3, 2016

@ianlancetaylor

Landed here with the same problem. The file command correctly produces image/svg+xml as an SVG file's mime type:

$ file -i /tmp/foo.svg
/tmp/foo.svg: image/svg+xml; charset=us-ascii
@bradfitz

This comment has been minimized.

Copy link
Member

commented Aug 3, 2016

http.DetectContentType is documented to be an implementation of https://mimesniff.spec.whatwg.org/ and that mimesniff spec doesn't define svg.

And as you found, mime.TypeByExtension has ".svg" in its built-in table:

https://github.com/golang/go/blob/release-branch.go1.6/src/mime/type.go#L35

So I don't think there's anything to do here.

@bradfitz bradfitz closed this Aug 3, 2016

@odeke-em

This comment has been minimized.

Copy link
Member

commented Aug 13, 2016

@bradfitz actually I reported an issue to whatwg whatwg/mimesniff#7, when this issue was filed here so that perhaps if they could define its spec, they could work on it, add it to the spec and we could add it in here. The issue that I filed is still open, but from the looks of it doesn't seem like they'll be adding it in. If they add it in, I'll ping this bug and we can see what we can.

@golang golang locked and limited conversation to collaborators Aug 13, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.