Upload file
POST
Swagger notice: Swagger 2.0 doesn't support file upload with a content-type different than application/x-www-form-urlencoded.
CoderSessionTokenheader
Coder-Session-Token<token>Content-Type*stringContent-Type must be application/x-tar or application/zip
Default
"application/x-tar"application/x-www-form-urlencoded- body
file*unknownFile to be uploaded. If using tar format, file must conform to ustar (pax may cause problems).
Returns existing file if duplicate
application/json- response
hash?stringFormat
uuidThe samples read CODER_URL and CODER_SESSION_TOKEN: set up your environment.
curl -X POST \ "$CODER_URL/api/v2/files" \ -H "Coder-Session-Token: $CODER_SESSION_TOKEN" \ -H "Content-Type: {Content-Type}" \ --data-binary "@{file}"import { readFile } from "node:fs/promises";const { CODER_URL, CODER_SESSION_TOKEN } = process.env;const url = `${CODER_URL}/api/v2/files`;const response = await fetch(url, { method: "POST", headers: { "Coder-Session-Token": CODER_SESSION_TOKEN, "Content-Type": "{Content-Type}", }, body: await readFile("{file}"),});console.log(response.status, await response.text());import osimport requestsurl = os.environ["CODER_URL"] + "/api/v2/files"token = os.environ["CODER_SESSION_TOKEN"]response = requests.post( url, headers={ "Coder-Session-Token": token, "Content-Type": "{Content-Type}", }, data=open("{file}", "rb"),)print(response.status_code, response.text)package mainimport ( "fmt" "io" "net/http" "os")func main() { body, err := os.Open("{file}") if err != nil { panic(err) } defer body.Close() url := os.Getenv("CODER_URL") + "/api/v2/files" token := os.Getenv("CODER_SESSION_TOKEN") req, err := http.NewRequest(http.MethodPost, url, body) if err != nil { panic(err) } req.Header.Set("Coder-Session-Token", token) req.Header.Set("Content-Type", "{Content-Type}") resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() out, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(resp.Status, string(out))}Example Response
{ "hash": "19686d84-b10d-4f90-b18e-84fd3fa038fd"}