Upload File
const form = new FormData();
form.append('file', '<string>');
const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
options.body = form;
fetch('https://api.decart.ai/v1/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.decart.ai/v1/files"
files = { "file": ("example-file", open("example-file", "rb")) }
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, files=files, headers=headers)
print(response.text)HttpResponse<String> response = Unirest.post("https://api.decart.ai/v1/files")
.header("x-api-key", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();val client = OkHttpClient()
val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001")
val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
val request = Request.Builder()
.url("https://api.decart.ai/v1/files")
.post(body)
.addHeader("x-api-key", "<api-key>")
.build()
val response = client.newCall(request).execute()import Foundation
let parameters = [
[
"name": "file",
"value": "<string>",
"fileName": "example-file"
]
]
let boundary = "---011000010111000001101001"
var body = ""
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["contentType"]!
let fileContent = try String(contentsOfFile: filename, encoding: .utf8)
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 postData = Data(body.utf8)
let url = URL(string: "https://api.decart.ai/v1/files")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.timeoutInterval = 10
request.allHTTPHeaderFields = ["x-api-key": "<api-key>"]
request.httpBody = postData
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))curl --request POST \
--url https://api.decart.ai/v1/files \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form file='@example-file'{
"id": "<string>",
"filename": "<string>",
"mime_type": "<string>",
"size_bytes": 123,
"created_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Files
Upload File
Upload a file once and get back a file_* reference id you can reuse across generations.
The same reference can be passed to realtime set_image as image_ref, avoiding a re-upload of the underlying bytes on every call.
POST
/
v1
/
files
Upload File
const form = new FormData();
form.append('file', '<string>');
const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
options.body = form;
fetch('https://api.decart.ai/v1/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.decart.ai/v1/files"
files = { "file": ("example-file", open("example-file", "rb")) }
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, files=files, headers=headers)
print(response.text)HttpResponse<String> response = Unirest.post("https://api.decart.ai/v1/files")
.header("x-api-key", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();val client = OkHttpClient()
val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001")
val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001--")
val request = Request.Builder()
.url("https://api.decart.ai/v1/files")
.post(body)
.addHeader("x-api-key", "<api-key>")
.build()
val response = client.newCall(request).execute()import Foundation
let parameters = [
[
"name": "file",
"value": "<string>",
"fileName": "example-file"
]
]
let boundary = "---011000010111000001101001"
var body = ""
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["contentType"]!
let fileContent = try String(contentsOfFile: filename, encoding: .utf8)
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 postData = Data(body.utf8)
let url = URL(string: "https://api.decart.ai/v1/files")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.timeoutInterval = 10
request.allHTTPHeaderFields = ["x-api-key": "<api-key>"]
request.httpBody = postData
let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))curl --request POST \
--url https://api.decart.ai/v1/files \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form file='@example-file'{
"id": "<string>",
"filename": "<string>",
"mime_type": "<string>",
"size_bytes": 123,
"created_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Authorizations
Body
multipart/form-data
Was this page helpful?
⌘I