<YOUR_ENVIRONMENT_ID>/files/<YOUR_FILE_NAME>
endpoint with your project's environment ID and your file name filled in. For example, 975bf280-fd91-488c-994c-2f04416e5ee3/files/my%20file%232.png
.
Content-type
header to the MIME type matching your file. For example, for a jpg image set the header to image/jpeg
.Content-length
header to a number matching the size of the file in bytes. For example, if the image is 12 kB, set the header to 12288
.ManagementClient
definition when using an SDK).
You can only upload files from local storage. The Management API doesn't support uploading files from a URL.
This returns a file_reference
object.
You'll use the file_reference
object to create the actual asset in the next step.
<YOUR_ENVIRONMENT_ID>/assets/external-id/<ASSET_EXTERNAL_ID>
endpoint with your project's environment ID and an external ID of your choice for the asset filled in.
In the body of the request, specify these properties:
file_reference
– use the file reference you obtained in the previous step to link the asset with your file.title
– specify a title for the asset (displayed in the administration interface).descriptions
– specify an asset description for each language.
language
– can be specified by its codename
or internal id
.description
– string with a description of the asset.{
"id": "8660e19c-7bbd-48a3-bb51-721934c7756c",
"type": "internal"
}
{
"id": "8d0baeb7-1165-5f13-b72e-b23fc39fc549",
"file_name": "brno-cafe-1080px.jpg",
"title": "Brno Cafe",
"size": 481939,
"image_width": 1920,
"image_height": 1440,
"type": "image/jpeg",
"file_reference": {
"id": "8660e19c-7bbd-48a3-bb51-721934c7756c",
"type": "internal"
},
"descriptions": [
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"description": "Cafe in Brno"
},
{
"language": {
"id": "d1f95fde-af02-b3b5-bd9e-f232311ccab8"
},
"description": "Café en Brno"
}
],
"external_id": "brno-cafe-image",
"last_modified": "2021-04-10T09:44:39.0111761Z"
}
// Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
using Kontent.Ai.Management;
var client = new ManagementClient(new ManagementOptions
{
ApiKey = "<YOUR_API_KEY>",
ProjectId = "<YOUR_ENVIRONMENT_ID>"
});
var filePath = Path.Combine(Environment.CurrentDirectory, "Data", "brno-cafe-1080px.jpg");
var contentType = "image/jpeg";
// Binary file reference to be used when adding a new asset
var response = await client.UploadFileAsync(new FileContentSource(filePath, contentType));
// Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
using Kontent.Ai.Management;
var client = new ManagementClient(new ManagementOptions
{
ApiKey = "<YOUR_API_KEY>",
ProjectId = "<YOUR_ENVIRONMENT_ID>"
});
// Uses the file reference object obtained in step 1
var createdAssetResponse = await client.UpsertAssetAsync(Reference.ByExternalId("which-brewing-fits-you"), new AssetUpsertModel
{
// 'fileReference' is only required when creating a new asset
// To create a file reference, see the "Upload a binary file" endpoint
FileReference = new FileReference
{
Id = "8660e19c-7bbd-48a3-bb51-721934c7756c",
Type = FileReferenceTypeEnum.Internal
},
Title = "Brno Cafe",
Descriptions = new AssetDescription[]
{
new AssetDescription
{
Description = "Cafe in Brno",
Language = Reference.ByCodename("en-US")
},
new AssetDescription
{
Description = "Café en Brno",
Language = Reference.ByCodename("es-ES")
}
}
});
my%20file%232.png
instead of my file#2.png
. The file will then show as my file#2.png
in the Kontent.ai UI.