How to use go-swagger to define an attachment download
up vote
2
down vote
favorite
I am using go-swagger
to download attachments. These are small multi-line files, and there is just a browser on the other end.
I tried defining the response as 'string'
, but can find no way to populate the payload with multiline text, it arrives with "rn" instead of newlines. I also tried 'string'
format 'binary'
, but then the client sees a response containing a Reader{}
. My content yaml
for the 200 response looks like this:
headers:
Content-Disposition:
type: string
pattern: attachment; filename="attachement.txt"
Content-Type:
type: string
pattern: application/octet-stream
schema:
type: string
I also tried 'string'
format 'byte'
, but I don't want a base64
encoded response.
Any advice on this?
This is what I have tried so far:
trying "string" format "byte"...
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload)
// fails.. will not accept payload other than strfmt.Bas64
trying "string"
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload.String())
// accepts payload, but 13/10 get converted into rn
trying "string" format "binary"
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(nopCloser(payload))
// accepts payload, but the browser sees a Reader{}
string file download attachment go-swagger
add a comment |
up vote
2
down vote
favorite
I am using go-swagger
to download attachments. These are small multi-line files, and there is just a browser on the other end.
I tried defining the response as 'string'
, but can find no way to populate the payload with multiline text, it arrives with "rn" instead of newlines. I also tried 'string'
format 'binary'
, but then the client sees a response containing a Reader{}
. My content yaml
for the 200 response looks like this:
headers:
Content-Disposition:
type: string
pattern: attachment; filename="attachement.txt"
Content-Type:
type: string
pattern: application/octet-stream
schema:
type: string
I also tried 'string'
format 'byte'
, but I don't want a base64
encoded response.
Any advice on this?
This is what I have tried so far:
trying "string" format "byte"...
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload)
// fails.. will not accept payload other than strfmt.Bas64
trying "string"
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload.String())
// accepts payload, but 13/10 get converted into rn
trying "string" format "binary"
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(nopCloser(payload))
// accepts payload, but the browser sees a Reader{}
string file download attachment go-swagger
Please show us some code and what you've tried so far.
– Phil
Sep 7 '17 at 7:04
I found the answer. I had used the text producer in the yaml file, I needed to make that into a octet-stream producer for this response by adding: produces: - application/octet-stream To the response yaml and re-building
– EdS
Sep 8 '17 at 7:20
Curiously, the above works for CURL client, but using a GO HTTP client still returns me a "Reader{}" - where ioutil.ReadAll() gives an empty string. This appears to be a limitation?
– EdS
Sep 13 '17 at 8:08
1
Anyone get this working? I too am interested....
– Dave Pascua
Jan 16 at 23:01
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am using go-swagger
to download attachments. These are small multi-line files, and there is just a browser on the other end.
I tried defining the response as 'string'
, but can find no way to populate the payload with multiline text, it arrives with "rn" instead of newlines. I also tried 'string'
format 'binary'
, but then the client sees a response containing a Reader{}
. My content yaml
for the 200 response looks like this:
headers:
Content-Disposition:
type: string
pattern: attachment; filename="attachement.txt"
Content-Type:
type: string
pattern: application/octet-stream
schema:
type: string
I also tried 'string'
format 'byte'
, but I don't want a base64
encoded response.
Any advice on this?
This is what I have tried so far:
trying "string" format "byte"...
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload)
// fails.. will not accept payload other than strfmt.Bas64
trying "string"
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload.String())
// accepts payload, but 13/10 get converted into rn
trying "string" format "binary"
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(nopCloser(payload))
// accepts payload, but the browser sees a Reader{}
string file download attachment go-swagger
I am using go-swagger
to download attachments. These are small multi-line files, and there is just a browser on the other end.
I tried defining the response as 'string'
, but can find no way to populate the payload with multiline text, it arrives with "rn" instead of newlines. I also tried 'string'
format 'binary'
, but then the client sees a response containing a Reader{}
. My content yaml
for the 200 response looks like this:
headers:
Content-Disposition:
type: string
pattern: attachment; filename="attachement.txt"
Content-Type:
type: string
pattern: application/octet-stream
schema:
type: string
I also tried 'string'
format 'byte'
, but I don't want a base64
encoded response.
Any advice on this?
This is what I have tried so far:
trying "string" format "byte"...
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload)
// fails.. will not accept payload other than strfmt.Bas64
trying "string"
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload.String())
// accepts payload, but 13/10 get converted into rn
trying "string" format "binary"
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(nopCloser(payload))
// accepts payload, but the browser sees a Reader{}
string file download attachment go-swagger
string file download attachment go-swagger
edited Sep 7 '17 at 8:41
asked Sep 7 '17 at 6:56
EdS
112
112
Please show us some code and what you've tried so far.
– Phil
Sep 7 '17 at 7:04
I found the answer. I had used the text producer in the yaml file, I needed to make that into a octet-stream producer for this response by adding: produces: - application/octet-stream To the response yaml and re-building
– EdS
Sep 8 '17 at 7:20
Curiously, the above works for CURL client, but using a GO HTTP client still returns me a "Reader{}" - where ioutil.ReadAll() gives an empty string. This appears to be a limitation?
– EdS
Sep 13 '17 at 8:08
1
Anyone get this working? I too am interested....
– Dave Pascua
Jan 16 at 23:01
add a comment |
Please show us some code and what you've tried so far.
– Phil
Sep 7 '17 at 7:04
I found the answer. I had used the text producer in the yaml file, I needed to make that into a octet-stream producer for this response by adding: produces: - application/octet-stream To the response yaml and re-building
– EdS
Sep 8 '17 at 7:20
Curiously, the above works for CURL client, but using a GO HTTP client still returns me a "Reader{}" - where ioutil.ReadAll() gives an empty string. This appears to be a limitation?
– EdS
Sep 13 '17 at 8:08
1
Anyone get this working? I too am interested....
– Dave Pascua
Jan 16 at 23:01
Please show us some code and what you've tried so far.
– Phil
Sep 7 '17 at 7:04
Please show us some code and what you've tried so far.
– Phil
Sep 7 '17 at 7:04
I found the answer. I had used the text producer in the yaml file, I needed to make that into a octet-stream producer for this response by adding: produces: - application/octet-stream To the response yaml and re-building
– EdS
Sep 8 '17 at 7:20
I found the answer. I had used the text producer in the yaml file, I needed to make that into a octet-stream producer for this response by adding: produces: - application/octet-stream To the response yaml and re-building
– EdS
Sep 8 '17 at 7:20
Curiously, the above works for CURL client, but using a GO HTTP client still returns me a "Reader{}" - where ioutil.ReadAll() gives an empty string. This appears to be a limitation?
– EdS
Sep 13 '17 at 8:08
Curiously, the above works for CURL client, but using a GO HTTP client still returns me a "Reader{}" - where ioutil.ReadAll() gives an empty string. This appears to be a limitation?
– EdS
Sep 13 '17 at 8:08
1
1
Anyone get this working? I too am interested....
– Dave Pascua
Jan 16 at 23:01
Anyone get this working? I too am interested....
– Dave Pascua
Jan 16 at 23:01
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
To reiterate the comment on the question, anyone who's trying to simply create an endpoint which allows for file download in go-swagger, just add an produces application/octet-stream
to the method.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
To reiterate the comment on the question, anyone who's trying to simply create an endpoint which allows for file download in go-swagger, just add an produces application/octet-stream
to the method.
add a comment |
up vote
0
down vote
To reiterate the comment on the question, anyone who's trying to simply create an endpoint which allows for file download in go-swagger, just add an produces application/octet-stream
to the method.
add a comment |
up vote
0
down vote
up vote
0
down vote
To reiterate the comment on the question, anyone who's trying to simply create an endpoint which allows for file download in go-swagger, just add an produces application/octet-stream
to the method.
To reiterate the comment on the question, anyone who's trying to simply create an endpoint which allows for file download in go-swagger, just add an produces application/octet-stream
to the method.
answered Nov 13 at 3:23
Nikhil Vandanapu
147311
147311
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46089789%2fhow-to-use-go-swagger-to-define-an-attachment-download%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please show us some code and what you've tried so far.
– Phil
Sep 7 '17 at 7:04
I found the answer. I had used the text producer in the yaml file, I needed to make that into a octet-stream producer for this response by adding: produces: - application/octet-stream To the response yaml and re-building
– EdS
Sep 8 '17 at 7:20
Curiously, the above works for CURL client, but using a GO HTTP client still returns me a "Reader{}" - where ioutil.ReadAll() gives an empty string. This appears to be a limitation?
– EdS
Sep 13 '17 at 8:08
1
Anyone get this working? I too am interested....
– Dave Pascua
Jan 16 at 23:01