mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* Nest jobs under an organization * Rename project parameter to parameter schema * Update references when computing project parameters * Add files endpoint * Allow one-off project import jobs * Allow variables to be injected that are not defined by the schema * Update API to use jobs first * Fix CLI tests * Fix linting * Fix hex length for files table * Reduce memory allocation for windows
29 lines
701 B
Go
29 lines
701 B
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/coder/coder/coderd"
|
|
)
|
|
|
|
const (
|
|
ContentTypeTar = "application/x-tar"
|
|
)
|
|
|
|
func (c *Client) UploadFile(ctx context.Context, contentType string, content []byte) (coderd.UploadFileResponse, error) {
|
|
res, err := c.request(ctx, http.MethodPost, "/api/v2/files", content, func(r *http.Request) {
|
|
r.Header.Set("Content-Type", contentType)
|
|
})
|
|
if err != nil {
|
|
return coderd.UploadFileResponse{}, err
|
|
}
|
|
defer res.Body.Close()
|
|
if res.StatusCode != http.StatusCreated {
|
|
return coderd.UploadFileResponse{}, readBodyAsError(res)
|
|
}
|
|
var resp coderd.UploadFileResponse
|
|
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
|
}
|