# Upload a file into an existing sandbox session POST https://api.chaser.sh/v1/sessions/{id}/upload Content-Type: multipart/form-data Upload one file into the filesystem of an existing sandbox session using multipart form data. Only sandbox sessions support file transfer. Reference: https://docs.chaser.sh/api-reference/chaser-core-api/sessions/upload-session-file ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: Chaser Core API version: 1.0.0 paths: /v1/sessions/{id}/upload: post: operationId: upload-session-file summary: Upload a file into an existing sandbox session description: >- Upload one file into the filesystem of an existing sandbox session using multipart form data. Only sandbox sessions support file transfer. tags: - subpackage_sessions parameters: - name: id in: path description: Session ID required: true schema: type: string - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: File uploaded content: application/json: schema: $ref: '#/components/schemas/SessionFileUploadResponse' '400': description: Invalid request or non-sandbox session content: application/json: schema: description: Any type '404': description: Session not found content: application/json: schema: description: Any type requestBody: description: Multipart form with `path` and `file` fields content: multipart/form-data: schema: type: object properties: file: type: string format: binary description: File contents as multipart binary payload. path: type: string description: Destination path inside the sandbox. required: - file - path servers: - url: https://api.chaser.sh - url: http://localhost:8000 components: schemas: SessionFileUploadResponse: type: object properties: path: type: string size: type: integer required: - path - size description: Response body for sandbox file upload. title: SessionFileUploadResponse securitySchemes: BearerAuth: type: http scheme: bearer ``` ## SDK Code Examples ```python import requests url = "https://api.chaser.sh/v1/sessions/id/upload" files = { "file": "open('', 'rb')" } payload = { "path": "/workspace/app.js" } headers = {"Authorization": "Bearer "} response = requests.post(url, data=payload, files=files, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.chaser.sh/v1/sessions/id/upload'; const form = new FormData(); form.append('file', ''); form.append('path', '/workspace/app.js'); const options = {method: 'POST', headers: {Authorization: 'Bearer '}}; options.body = form; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.chaser.sh/v1/sessions/id/upload" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"path\"\r\n\r\n/workspace/app.js\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.chaser.sh/v1/sessions/id/upload") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"path\"\r\n\r\n/workspace/app.js\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.chaser.sh/v1/sessions/id/upload") .header("Authorization", "Bearer ") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"path\"\r\n\r\n/workspace/app.js\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php request('POST', 'https://api.chaser.sh/v1/sessions/id/upload', [ 'multipart' => [ [ 'name' => 'file', 'filename' => '', 'contents' => null ], [ 'name' => 'path', 'contents' => '/workspace/app.js' ] ] 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.chaser.sh/v1/sessions/id/upload"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"path\"\r\n\r\n/workspace/app.js\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Authorization": "Bearer "] let parameters = [ [ "name": "file", "fileName": "" ], [ "name": "path", "value": "/workspace/app.js" ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error as Any) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "https://api.chaser.sh/v1/sessions/id/upload")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```