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

mime/multipart: CreateFormFile does not allow setting the Content-Type for the file. #16425

Closed
pwhelan opened this Issue Jul 19, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@pwhelan

pwhelan commented Jul 19, 2016

Please answer these questions before submitting your issue. Thanks!

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

Go 1.6.2

  1. What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

  1. What did you do?

I used mime/multipart CreateFormFile but was unable to set the Content-Type for the part.

  1. What did you expect to see?

Content-Disposition: form-data; name="photo"; filename="photo.jpg"
Content-Type: image/jpeg

xxxxxxxxxxxxxxxxxxxxxxx

  1. What did you see instead?

Content-Disposition: form-data; name="photo"; filename="photo.jpg"
Content-Type: application/octet-stream

xxxxxxxxxxxxxxxxxxxxxxx

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz Jul 19, 2016

Member

Use CreatePart.

CreateFormFile is a very thin wrapper around CreatePart. Click https://golang.org/pkg/mime/multipart/#Writer.CreateFormField and then click the CreateFormFile heading to see its source code.

Member

bradfitz commented Jul 19, 2016

Use CreatePart.

CreateFormFile is a very thin wrapper around CreatePart. Click https://golang.org/pkg/mime/multipart/#Writer.CreateFormField and then click the CreateFormFile heading to see its source code.

@bradfitz bradfitz closed this Jul 19, 2016

@pwhelan

This comment has been minimized.

Show comment
Hide comment
@pwhelan

pwhelan Jul 20, 2016

I did that. It just seems to me like an absolutely necessary feature to make the method useful at all.

pwhelan commented Jul 20, 2016

I did that. It just seems to me like an absolutely necessary feature to make the method useful at all.

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz Jul 20, 2016

Member

Where do you draw the line? Just content type? Content type and disposition? And Filename? All permutations thereof? Method for each?

Everybody's opinions on the most useful parts vary, I'm sure.

If you come back with some data suggesting that most users need a certain API which we don't provide and everybody is doing a tedious thing we could make easier, then I think we can make changes.

See https://medium.com/google-cloud/analyzing-go-code-with-bigquery-485c70c3b451#.9mr0dcybl for how to do some SQL queries against all code on Github.

/cc @campoy

Member

bradfitz commented Jul 20, 2016

Where do you draw the line? Just content type? Content type and disposition? And Filename? All permutations thereof? Method for each?

Everybody's opinions on the most useful parts vary, I'm sure.

If you come back with some data suggesting that most users need a certain API which we don't provide and everybody is doing a tedious thing we could make easier, then I think we can make changes.

See https://medium.com/google-cloud/analyzing-go-code-with-bigquery-485c70c3b451#.9mr0dcybl for how to do some SQL queries against all code on Github.

/cc @campoy

@pwhelan

This comment has been minimized.

Show comment
Hide comment

pwhelan commented Jul 20, 2016

will do.

@golang golang locked and limited conversation to collaborators Jul 20, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.