Docs Guides
Files
Uploading, allowed types, and how learners download.
Upload with multipart/form-data, field name file.
curl -X POST "$LMS_URL/api/v1/assets" \
-H "X-API-Key: $LMS_KEY" \
-F "file=@handbook.pdf"import { openAsBlob } from 'node:fs'
const LMS_URL = process.env.LMS_URL
const LMS_KEY = process.env.LMS_KEY
const form = new FormData()
form.append("file", await openAsBlob("handbook.pdf"), "handbook.pdf")
const res = await fetch(`${LMS_URL}/api/v1/assets`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY },
body: form,
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data = await res.json()import { openAsBlob } from 'node:fs'
const LMS_URL = process.env.LMS_URL!
const LMS_KEY = process.env.LMS_KEY!
const form = new FormData()
form.append("file", await openAsBlob("handbook.pdf"), "handbook.pdf")
const res = await fetch(`${LMS_URL}/api/v1/assets`, {
method: 'POST',
headers: { "X-API-Key": LMS_KEY },
body: form,
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data: unknown = await res.json()import os
import requests
LMS_URL = os.environ["LMS_URL"]
HEADERS = {"X-API-Key": os.environ["LMS_KEY"]}
res = requests.post(f"{LMS_URL}/api/v1/assets", headers=HEADERS, files={"file": open("handbook.pdf", "rb")}, timeout=10)
res.raise_for_status()
data = res.json()import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
public class Request {
public static void main(String[] args) throws Exception {
String lmsUrl = System.getenv("LMS_URL");
String lmsKey = System.getenv("LMS_KEY");
String boundary = "----lms" + System.nanoTime();
var form = new ByteArrayOutputStream();
form.write(("--" + boundary + "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"handbook.pdf\"\r\n"
+ "Content-Type: application/octet-stream\r\n\r\n").getBytes());
form.write(Files.readAllBytes(Path.of("handbook.pdf")));
form.write(("\r\n--" + boundary + "--\r\n").getBytes());
var request = HttpRequest.newBuilder(URI.create(lmsUrl + "/api/v1/assets"))
.header("X-API-Key", lmsKey)
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.method("POST", HttpRequest.BodyPublishers.ofByteArray(form.toByteArray()))
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.statusCode() + " " + response.body());
System.out.println(response.body());
}
}require "net/http"
require "json"
lms_url = ENV.fetch("LMS_URL")
uri = URI("#{lms_url}/api/v1/assets")
request = Net::HTTP::Post.new(uri, "X-API-Key" => ENV.fetch("LMS_KEY"))
request.set_form([["file", File.open("handbook.pdf")]], "multipart/form-data")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
raise "#{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)<?php
$lmsUrl = getenv('LMS_URL');
$ch = curl_init("$lmsUrl/api/v1/assets");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('LMS_KEY')],
CURLOPT_POSTFIELDS => ["file" => new CURLFile("handbook.pdf")],
]);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 300) {
throw new RuntimeException($response);
}
$data = json_decode($response, true);package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var form bytes.Buffer
w := multipart.NewWriter(&form)
part, _ := w.CreateFormFile("file", "handbook.pdf")
f, _ := os.Open("handbook.pdf")
io.Copy(part, f)
w.Close()
req, _ := http.NewRequest("POST", os.Getenv("LMS_URL") + "/api/v1/assets", &form)
req.Header.Set("X-API-Key", os.Getenv("LMS_KEY"))
req.Header.Set("Content-Type", w.FormDataContentType())
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
panic(fmt.Sprintf("%d %s", res.StatusCode, data))
}
fmt.Println(string(data))
}Allowed types#
PNG, JPEG, GIF, WebP, MP4, WebM, MP3, M4A, PDF, plain text, CSV, ZIP, and Word, Excel and PowerPoint documents. Anything else returns 415.
Important
SVG and HTML are refused, because they can carry script. Convert logos to PNG.
How files are stored#
- The server generates the storage key; your filename is sanitised and kept only as a label.
- Each file records its size and SHA-256.
- Downloads use the stored content type,
X-Content-Type-Options: nosniffand a download disposition.
Using a file#
Reference its id in a block (VIDEO, IMAGE, FILE), a course cover, or a certificate design. You can’t delete a file that is still in use (409).
Learners#
Learners download files through their enrollment (/me/enrollments/{e}/assets/{id}/content). Only files used by their course version are served.
Note
Files are stored on the server’s disk (STORAGE_DIR). Object storage such as S3 is on the roadmap.