Create file
curl --request POST \
--url https://api.enterprise.sandbox.uphold.com/core/files \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"category": "image",
"contentType": "image/png",
"metadata": {
"externalId": 123
}
}
'import requests
url = "https://api.enterprise.sandbox.uphold.com/core/files"
payload = {
"category": "image",
"contentType": "image/png",
"metadata": { "externalId": 123 }
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({category: 'image', contentType: 'image/png', metadata: {externalId: 123}})
};
fetch('https://api.enterprise.sandbox.uphold.com/core/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.enterprise.sandbox.uphold.com/core/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'category' => 'image',
'contentType' => 'image/png',
'metadata' => [
'externalId' => 123
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.enterprise.sandbox.uphold.com/core/files"
payload := strings.NewReader("{\n \"category\": \"image\",\n \"contentType\": \"image/png\",\n \"metadata\": {\n \"externalId\": 123\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.enterprise.sandbox.uphold.com/core/files")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"category\": \"image\",\n \"contentType\": \"image/png\",\n \"metadata\": {\n \"externalId\": 123\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.enterprise.sandbox.uphold.com/core/files")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"category\": \"image\",\n \"contentType\": \"image/png\",\n \"metadata\": {\n \"externalId\": 123\n }\n}"
response = http.request(request)
puts response.read_body{
"file": {
"id": "38cce774-b225-41ed-a9fd-f9c9777a13de",
"status": "pending",
"category": "image",
"contentType": "image/png",
"upload": {
"url": "https://example.com/upload",
"formData": {
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "ASIE4FQORBNQHNQD5CG6/20240801/us-east-1/s3/aws4_request",
"X-Amz-Date": "20240801T102500Z",
"X-Amz-Security-Token": "IQoJb3JpZ2luX2VjEIv//////////...JBr6h2HkzH/aFSArQcs=",
"X-Amz-Signature": "b4da8cf1a59327988a8108c965a4789fc8ba2d20f5bffda076106b2b254def29",
"Key": "4c13b6f5-987e-43df-bc12-042b58307a80",
"Policy": "eyJjb25kaXRpb25zIjpbeyJidWN...TA6MjU6MDAuMjAyWiJ9"
},
"expiresAt": "2024-03-13T20:20:39.000Z"
}
}
}Files
Create file
Create a new file.
POST
/
core
/
files
Create file
curl --request POST \
--url https://api.enterprise.sandbox.uphold.com/core/files \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"category": "image",
"contentType": "image/png",
"metadata": {
"externalId": 123
}
}
'import requests
url = "https://api.enterprise.sandbox.uphold.com/core/files"
payload = {
"category": "image",
"contentType": "image/png",
"metadata": { "externalId": 123 }
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({category: 'image', contentType: 'image/png', metadata: {externalId: 123}})
};
fetch('https://api.enterprise.sandbox.uphold.com/core/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.enterprise.sandbox.uphold.com/core/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'category' => 'image',
'contentType' => 'image/png',
'metadata' => [
'externalId' => 123
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.enterprise.sandbox.uphold.com/core/files"
payload := strings.NewReader("{\n \"category\": \"image\",\n \"contentType\": \"image/png\",\n \"metadata\": {\n \"externalId\": 123\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.enterprise.sandbox.uphold.com/core/files")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"category\": \"image\",\n \"contentType\": \"image/png\",\n \"metadata\": {\n \"externalId\": 123\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.enterprise.sandbox.uphold.com/core/files")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"category\": \"image\",\n \"contentType\": \"image/png\",\n \"metadata\": {\n \"externalId\": 123\n }\n}"
response = http.request(request)
puts response.read_body{
"file": {
"id": "38cce774-b225-41ed-a9fd-f9c9777a13de",
"status": "pending",
"category": "image",
"contentType": "image/png",
"upload": {
"url": "https://example.com/upload",
"formData": {
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "ASIE4FQORBNQHNQD5CG6/20240801/us-east-1/s3/aws4_request",
"X-Amz-Date": "20240801T102500Z",
"X-Amz-Security-Token": "IQoJb3JpZ2luX2VjEIv//////////...JBr6h2HkzH/aFSArQcs=",
"X-Amz-Signature": "b4da8cf1a59327988a8108c965a4789fc8ba2d20f5bffda076106b2b254def29",
"Key": "4c13b6f5-987e-43df-bc12-042b58307a80",
"Policy": "eyJjb25kaXRpb25zIjpbeyJidWN...TA6MjU6MDAuMjAyWiJ9"
},
"expiresAt": "2024-03-13T20:20:39.000Z"
}
}
}
Uploading a file is a two step process. You start by creating a placeholder for the file and then using the
upload details of the response to actually upload the file. Each file has a unique id which is used across the API when you need to reference it.
You can optionally include custom entity metadata in the metadata field to store your own business data (e.g., descriptions, related entity IDs, processing metadata). If not provided during creation, you can add it later using Set metadata.
Below you will find examples in several programming languages to do the upload:
Node.js
Node.js
The following example uses
file-type package to determine the content-type of the file.import { fileTypeFromFile } from 'file-type';
import fs from 'node:fs';
// Function to upload file.
// Takes `file` record from the response and `filePath` which points to the file on disk that needs to be uploaded.
const uploadFile = async (file, filePath) => {
const { url, formData } = file.upload;
// Add form data.
const form = new FormData();
for (const [key, value] of Object.entries(formData)) {
form.append(key, value);
}
// Add content type, determined by file-type package.
// This must match the `contentType` of the file record.
const { mime } = await fileTypeFromFile(filePath);
form.append('Content-Type', mime);
// Add file blob.
const blob = await fs.openAsBlob(filePath)
form.append('File', blob);
const response = await fetch(url, {
method: 'POST',
body: form,
});
if (!response.ok) {
throw new Error(`Failed to upload file: ${response.statusText}`);
}
console.log('File uploaded!')
};
Authorizations
OAuth 2.0 authentication.
Body
application/json
Was this page helpful?
⌘I