Support Retrieve file content API (#347) (#348)

* Support Retrieve file content API (#347)

* add timeout test for GetFileContent (#347)
This commit is contained in:
渡邉祐一 / Yuichi Watanabe
2023-06-11 17:49:57 +09:00
committed by GitHub
parent 06b16a7281
commit a243e7331f
6 changed files with 216 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"os"
)
@@ -103,3 +104,26 @@ func (c *Client) GetFile(ctx context.Context, fileID string) (file File, err err
err = c.sendRequest(req, &file)
return
}
func (c *Client) GetFileContent(ctx context.Context, fileID string) (content io.ReadCloser, err error) {
urlSuffix := fmt.Sprintf("/files/%s/content", fileID)
req, err := c.requestBuilder.Build(ctx, http.MethodGet, c.fullURL(urlSuffix), nil)
if err != nil {
return
}
c.setCommonHeaders(req)
res, err := c.config.HTTPClient.Do(req)
if err != nil {
return
}
if isFailureStatusCode(res) {
err = c.handleErrorResp(res)
return
}
content = res.Body
return
}