Dec 24, 2024
Enterprises currently on AEM or another DXP considering a move to Adobe as a Cloud Service (AEMaaCS) will likely have an extensive library of assets that need to be migrated to the cloud.
AEMaaCS underwent a significant architectural change in how assets are ingested and managed. While authors may not notice much difference, this change represents a major technical improvement.
With this shift, the process of uploading assets has been repurposed. In this blog, we will explore everything you need to know about uploading assets into AEMaaCS using the aem-upload library.
Before discussing AEM Upload, we need to provide some context, particularly the methods that were and are available for uploading assets to AEM and how assets are ingested in AEMaaCS today.
Available Methods to Upload Assets to Adobe Experience Manager (AEM)
Over time and across various versions, Adobe Experience Manager (AEM) has introduced several methods for creating and managing assets. While these methods may differ and are not always directly comparable, each could still be valid depending on the scenario and business requirements.
Method / Tooling |
Short Description |
Intended Audience |
Common Use Case |
Version |
---|---|---|---|---|
Using the AEM Author Interface (Assets UI) |
AEM ships with a powerful and easy-to-use UI that allows users with the proper permissions to upload assets directly to AEM |
AEM Authors / Content Authors |
Regular work of a content author |
AEM on-premise / AEMaaCS |
AEM Desktop App |
AEM Desktop app is a local application that connects to AEM author, simplifying access to asset management in AEM. |
AEM Authors / Content Authors |
Regular work of a content author |
AEM on-premise |
Bulk Import Tool |
The Bulk Import tool allows you to import assets in bulk from cloud storage safely and efficiently. |
AEM Administrators |
Special large migrations |
AEMaaCS |
AEM Java API’s (Sling / JCR) |
This Java API provides developers with a way to upload assets programmatically. However, Adobe has deprecated it and no longer recommends it. |
Developers |
Interact with Assets via OSGi components (bundles). |
AEM on-premise |
Assets HTTP API |
This is a set of RESTful services that allows developers to interact programmatically with AEM's Digital Asset Management (DAM) features. |
Developers |
Interact with Assets in a headless manner. |
AEM on-premise / AEMaaCS |
AEM Upload through directly HTTP API |
Using HTTP APIs, you can directly upload assets to cloud storage |
Developers |
Upload assets in bulk or in a headless fashion |
AEMaaCS |
AEM Upload Library |
This library wraps the aforementioned HTTP APIs, simplifying their usage. |
Developers |
Upload assets in bulk or in a headless fashion |
AEMaaCS |
Uploading Assets in AEMaaCS
How It Works
In contrast to AEM on-premises, where you have only one step to upload an asset, AEMaaCS involves three steps and coordination for a successful upload. There are several blogs and official documentation that thoroughly explain this process. As a result, we will simply summarize the three steps involved in uploading assets in AEMaaCS:
-
Initiate the Upload Request. The client submits an HTTP request to inform AEM that it intends to upload a new binary.
-
Upload Binary. The binary is uploaded to Cloud Storage using the URIs provided in the first step.
-
Notify Request Completion. Finally, the client informs AEM that the binary contents have been successfully uploaded, making the binary available in the UI.
One last important point is that the upload process is intended to occur outside the JVM. In other words, you should not perform it within the AEM environment. Instead, using a separate process to manage the asset upload is preferable.
API’s Reference
Upload Step |
Method |
URL (Example) |
Description |
---|---|---|---|
Start Upload Request |
|
|
The URL is composed of the folder path where the asset will be uploaded, along with the selector and the extension |
Upload URL |
|
|
These URLs may vary based on the asset size and will be included in the response to the Initiate Upload call. |
Notify Request Completion |
|
|
This URL is also part of the response to the Initiate Upload call |
AEM Upload Library
As explained in the previous section, uploading assets to AEMaaCS involves three steps. This process can be inconvenient or tedious, so Adobe introduced the AEM Upload Library to alleviate that workload. This open-source project streamlines these steps into a single, easy-to-use way for asset uploads. The AEM Upload Library can be utilized as a Node module or as a command-line interface (CLI), enabling you to create your own separate external process outside AEM (JVM) for greater flexibility to meet various scenarios and requirements.
**Disclaimer: You can upload an asset directly using the Adobe APIs. This library is intended to streamline that process. Consider this tool an additional option.
Let’s See It In Action
Now, let’s demonstrate how to upload an asset from the desktop to AEMaaCS via an API. The API will be invoked using Postman and built using Node with Express.
Here is the code for the API:
const express = require("express");
const multer = require('multer');
const DirectBinary = require('@adobe/aem-upload');
// Init vars
const targetUrl = 'https://author-xxx-xxx.adobeaemcloud.com/content/dam/demo';
const codes = DirectBinary.DirectBinaryUploadErrorCodes;
const upload = new DirectBinary.DirectBinaryUpload();
// TODO: Make sure to manage your token properly not this way!
const ACCESS_TOKEN = "xxxx";
app.post("/upload", uploadMulter.single('file'), (req, res) => {
let uploadFiles = [];
// Access the blob from request
let assetToUpload = {
"fileName": req.file.originalname,
"fileSize": req.file.size,
"versionLabel": "original",
"blob": req.file.buffer,
"replace": true
};
uploadFiles.push(assetToUpload);
const options = new DirectBinary.DirectBinaryUploadOptions()
.withUrl(targetUrl)
.withUploadFiles(uploadFiles)
.withHttpOptions({
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`
}
});
upload.uploadFiles(options)
.then(result => {
const { errors = [], detailedResult = [] } = result;
detailedResult.forEach(resultJson => {
console.log(`Attempting to upload to ${resultJson.fileUrl}`);
console.log(`With result: ${JSON.stringify(resultJson.result)}`);
});
errors.forEach(error => {
// TODO: Error handling and Re-try as needed
});
})
.catch(err => {
console.log(`Error ${err}`)
res.status(500).json({status:500, message: "Oops something goes wrong!"});
});
res.status(200).json({status:200, message: "Asset Upload Succesfully"});
});
app.listen(3000);
Let’s highlight the important parts of this code:
-
Line 2: Imports
Multer
, a Node library for uploading files, making it easier to process file uploads in requests. -
Line 3: Imports the
aem-upload
library (Node module flavor) -
Line 8: Creates an instance of
DirectBinaryUpload
from the AEM Upload library to manage uploads. -
Line 13: This line defines a POST endpoint
/upload
that accepts a single file under the field name 'file' -
Line 25: This constructs the upload options, setting the target URL, the files to upload, and the HTTP headers, including the authorization token
-
Line 34: This line initiates the upload process using the options defined earlier
Now, we can run the Node server and then invoke a new /upload
endpoint using Postman like this:
With that unique call, we can see that the asset has been successfully uploaded to the AEMaaCS instance.
A similar approach can be taken using the AEM Upload CLI, a plugin for the Adobe I/O CLI.
Wrapping Up
AEM Upload makes it easier for developers to migrate a library of content assets to the cloud for use in AEMaaCS. However, companies must also consider other areas.
Oshyn is an Adobe partner that can support you with multiple aspects of your journey with the Adobe DXP suite, including design planning, development, post-launch enhancements, and maintenance. If you're considering migrating to AEMaaCS, starting early can make a massive difference. See our blog for tips on how to get prepared: Start Early for a Successful AEMaaCS Migration.
References
Related Insights
-
-
Jonathan Saurez
Unit Testing Using AEM Mocks
Detecting Code Flaws Before They Cause Outages for Your Users
-
Esteban Bustamante
Transition Sites to AEM Using Bulk Importer
Migrate Assets into AEMaaCS
-
Esteban Bustamante
How to Add Functionality to your AEM Site
When the Standard Features aren't Adequate
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.