Uploaded files
Create an uploaded file
Create an uploaded file after uploading the raw file to our file server.
The entire flow for uploaded files to us is as follows:
- Call the
generate-upload-urlendpoint to initiate an upload. - POST your file to the returned URL, including the returned form data.
- Call this endpoint to register your uploaded file with our system.
It would look something like this in python:
import requests
api_session = requests.Session()
api_session.headers.update({"Authorization": f"Bearer {API_KEY}"})
s3_session = requests.Session()
# Step 1: Get an upload URL.
response = api_session.post(
f"{VETCOVE_API_SERVER}/ext/v2/uploaded-files/generate-upload-url/",
json={
"filename": "example.jpg",
"content_type": "image/jpg"
}
)
response.raise_for_status()
# Step 2: Extract the necessary values from the response.
key = response.json()["key"]
upload_url = response.json()["url"]
upload_post_data = response.json()["post_data"]
# Step 3: Upload the file to our file server (Amazon S3).
with open(LOCAL_PATH_TO_FILE_UPLOAD, "rb") as f:
response = s3_session.post(upload_url, data=upload_post_data, files={"file": f})
response.raise_for_status()
# Step 4: Register the uploaded file with Vetcove.
response = api_session.post(
f"{VETCOVE_API_SERVER}/ext/v2/uploaded-files/",
json={
"filename": "example.jpg",
"key": key,
}
)
response.raise_for_status()
print(f"Created uploaded file with id {response.json()['id']}")
POST
/
ext
/
v2
/
uploaded-files
/
Create an uploaded file
curl --request POST \
--url https://connect.vetcove.com/ext/v2/uploaded-files/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filename": "<string>",
"key": "<string>"
}
'import requests
url = "https://connect.vetcove.com/ext/v2/uploaded-files/"
payload = {
"filename": "<string>",
"key": "<string>"
}
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({filename: '<string>', key: '<string>'})
};
fetch('https://connect.vetcove.com/ext/v2/uploaded-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://connect.vetcove.com/ext/v2/uploaded-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([
'filename' => '<string>',
'key' => '<string>'
]),
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://connect.vetcove.com/ext/v2/uploaded-files/"
payload := strings.NewReader("{\n \"filename\": \"<string>\",\n \"key\": \"<string>\"\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://connect.vetcove.com/ext/v2/uploaded-files/")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"filename\": \"<string>\",\n \"key\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://connect.vetcove.com/ext/v2/uploaded-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 \"filename\": \"<string>\",\n \"key\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"filename": "<string>",
"filesize": 123,
"id": 123,
"url": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Response
201 - application/json
Created
Was this page helpful?
⌘I
Create an uploaded file
curl --request POST \
--url https://connect.vetcove.com/ext/v2/uploaded-files/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filename": "<string>",
"key": "<string>"
}
'import requests
url = "https://connect.vetcove.com/ext/v2/uploaded-files/"
payload = {
"filename": "<string>",
"key": "<string>"
}
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({filename: '<string>', key: '<string>'})
};
fetch('https://connect.vetcove.com/ext/v2/uploaded-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://connect.vetcove.com/ext/v2/uploaded-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([
'filename' => '<string>',
'key' => '<string>'
]),
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://connect.vetcove.com/ext/v2/uploaded-files/"
payload := strings.NewReader("{\n \"filename\": \"<string>\",\n \"key\": \"<string>\"\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://connect.vetcove.com/ext/v2/uploaded-files/")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"filename\": \"<string>\",\n \"key\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://connect.vetcove.com/ext/v2/uploaded-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 \"filename\": \"<string>\",\n \"key\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"filename": "<string>",
"filesize": 123,
"id": 123,
"url": "<string>"
}