First create the file in the folder,
{
"fields": {
"_nameInvariantCulture": {
"*": "img.jpg"
},
},
"fieldTemplateSystemId": "409f72c2-cea9-4917-8d60-39d475e2c565",
"folderSystemId": "fa416bd4-33f4-414f-97d8-669e7c91e27f"
}
Complete request with curl
curl -X POST "https://demoadmin.litium.com/Litium/api/admin/media/files" -H "accept: */*" -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" -d "{ \"fields\": { \"_nameInvariantCulture\": { \"*\": \"img.jpg\" }, }, \"fieldTemplateSystemId\": \"409f72c2-cea9-4917-8d60-39d475e2c565\", \"folderSystemId\": \"fa416bd4-33f4-414f-97d8-669e7c91e27f\"}"
Response
{
"accessControlList": [
{
"groupSystemId": "5b521f8c-a7a2-44e0-ab76-1c60d740bded",
"operation": "Entity/Read"
}
],
"fields": {
"_nameInvariantCulture": {
"*": "img.jpg"
}
},
"fieldTemplateSystemId": "409f72c2-cea9-4917-8d60-39d475e2c565",
"folderSystemId": "fa416bd4-33f4-414f-97d8-669e7c91e27f",
"systemId": "293b8e24-6b21-42d4-b7bb-a6b9087c4c36",
"trashCanStatus": 1
}
Upload the image to the file, this is a multipart/form-data request, not a regular application/json request
curl -X PUT "https://demoadmin.litium.com/Litium/api/admin/media/files/293b8e24-6b21-42d4-b7bb-a6b9087c4c36/upload" -H "accept: */*" -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: multipart/form-data" -F "fileName=@/path/to/your/file.jpg"
AI generated c# version of above
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var token = "YOUR_TOKEN";
var baseUrl = "https://demoadmin.litium.com/Litium/api/admin/media/files";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
// 1) Create media file
var json = @"{
""fields"": {
""_nameInvariantCulture"": { ""*"": ""img.jpg"" }
},
""fieldTemplateSystemId"": ""409f72c2-cea9-4917-8d60-39d475e2c565"",
""folderSystemId"": ""fa416bd4-33f4-414f-97d8-669e7c91e27f""
}";
var createResponse = await client.PostAsync(baseUrl,
new StringContent(json, Encoding.UTF8, "application/json"));
createResponse.EnsureSuccessStatusCode();
var createContent = await createResponse.Content.ReadAsStringAsync();
// ✅ Extract systemId using System.Text.Json
using var doc = JsonDocument.Parse(createContent);
var root = doc.RootElement;
var systemId = root.GetProperty("systemId").GetString();
if (string.IsNullOrWhiteSpace(systemId))
{
throw new InvalidOperationException("systemId not found in response.");
}
// 2) Upload file
var uploadUrl = $"{baseUrl}/{systemId}/upload";
using var form = new MultipartFormDataContent();
var filePath = @"C:\path\to\your\file.jpg";
using var fileStream = System.IO.File.OpenRead(filePath);
form.Add(new StreamContent(fileStream), "fileName", "file.jpg");
var uploadResponse = await client.PutAsync(uploadUrl, form);
uploadResponse.EnsureSuccessStatusCode();
var uploadContent = await uploadResponse.Content.ReadAsStringAsync();
Console.WriteLine("Upload Response: " + uploadContent);
}
}