Media Admin API running into issue

We are working on the latest Litium Empty Web accelerator project with latest storefront

We’re trying to upload media using the Admin API but are running into issues.
A PUT request to /Litium/api/admin/media/files/{systemId}/upload returns a 404.

A POST request to /Litium/api/admin/media/files requires a blobUri.

Please provide documentation or a working example of how to upload media files using the Admin API.

Litium version: [8.24.1]

Hi, did you try with /litium/api/admin/media/files/{{systemId}/upload? Not capital letter at the beginning. I don’t know if it affects but worth for a try :slight_smile: Did you try it with Postman? Otherwise create a ticket by sending a mail to support@litium.com so that we can handle your case.

Tried with postman and swagger. Got 404 error. Will send a ticket to support

We managed to sort it out — we first created the file using the POST endpoint and used a blobUri in the format litium.blob://media/[systemid-with-dashes-removed]. After that, the PUT upload worked as expected.
It would still be very helpful to have accessible documentation covering this flow, especially around generating the blobUri and the correct sequence for creating and uploading media.

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);
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.