Adobe Campaign, Marketing Automation

Automate file resources upload with a workflow

Automate file resources upload with a workflow

Sometimes, you will reach a point where you want to upload file resources from a script. Although there are hints on the Experience League, even with those, this problem has caused me some troubles.

However, challenges and troubles are what I seek. I have decided to map this functionality, which can become handy once in a blue moon. For example you want to attach dynamic attachments to recipient delivery or add before made qr codes or vouchers to the email content.

For those seeking a quick answer without delving into this blog, the solution lies within the nms:assetIntegration.js JavaScript library. Check out the method call uploadContentToCampaign for the answer you’re looking for.

Building technical workflow

We can set up a technical workflow that triggers every xy minutes to check for the existence of a file in a remote folder. If the file exists, we will load it into Adobe Campaign. The actual file, along with its path, is automatically saved for us in the workflow variables vars.filename.

Adobe Campaign Classic - autoamtivally upload file resources

For this purpose we will use File transfer activity. Where first will be set to Test to see if file exists and second to File download. After we process file with the workflow we add JavaScript activity to save and publish our file

Adobe Campaign Classic - upload resource workflow setup

Saving and publishing file

Last but not least is the step where we save the file loaded with File transfer activiry as resources and publish them to the vast internet. There are Experience League community posts discussing this topic, especially the issues with publishing resources. However, for my recent endeavor, none of those—many of which were my own—hints helped.

var fileName,
    uploadPath = (application.instanceVarDir + "/upload/").toString(),
    patternRemoveTimestamp = /_\d{14}[a-z]/;

String.prototype.getFileExtension = function() {
  // Regular expression to match the file extension
  var regex = /(?:\.([^.]+))?$/,
      extension = regex.exec(this)[1];
  return extension ? extension.toLowerCase() : null;

fileName = (vars.filename).toString().split("/").pop();
fileExtension =  fileName.getFileExtension();
fileName = fileName.replace(patternRemoveTimestamp, "");
md5FileName = digestStrMd5(fileName);

file = new File(vars.filename);
  logWarning('File' + vars.filename + " is missing");
} else {
  if(file.copyTo(uploadPath + md5FileName + "." + fileExtension)){
    fileRes = NLWS.xtkFileRes.create();
    fileRes.storageType = 5;
    fileRes.useMd5AsFilename = 1;
    fileRes.publish = true;
    fileRes.userContentType = 0;
    fileRes.label = fileName;
    fileRes.folder_id = 11111;
    fileRes.md5 = md5FileName;
    fileRes.fileName = md5FileName + "." + fileExtension;
    fileRes.originalName = md5FileName + "." + fileExtension;  
    logInfo('uploaded file:' + fileName);
  1. String Prototype Extension:
    • Added getFileExtension method to the String prototype to extract file extensions.
  2. Filename and Extension Extraction:
    • Extracted the filename from vars.filename.
    • Extracted the file extension using the custom getFileExtension method.
  3. Timestamp Removal and MD5 Hashing:
    • Removed the timestamp from the filename using a regular expression.
    • Generated an MD5 hash of the modified filename.
  4. File Handling, upload and publish:
    • Checked if the specified file exists.
    • Copied the file to the upload path with the new filename (MD5 hash + original file extension).

The difference between the code that is online and the code found in the library is the function called WebPostUpload, which, by its JSAPI definition, ‘finalizes the storage of the resource after the upload (from a web page) to the server depending on the storage type used. It recovers the codepage and the content type. I will try to use it without next.

What I need to explore is the possibility of using human-readable text as a filename, as it seems that only an MD5 hash can be used in naming. When I used human-readable text as the filename, the process froze, and I had to kill the workflow.

Oh hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

#adobe campaign classic #JavaScript #programming #workflow
Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in problem-solving, process automation, and driving innovation for clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified), as well as 1x Salesforce Associate certified.

Moreover, I serve as a community advisor for Adobe Campaign, providing expert insights and guidance.

Beyond my professional pursuits, I explore various programming languages, CMSs, and frameworks, enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

2 thoughts on “Automate file resources upload with a workflow

  1. Hi Marcel,

    Thanks for the post. It is really helpful.

    Do we have something to download files from my server?
    The issue is we don’t have access to SFTP. I am expecting a code that will connect with my Adobe campaign server and download the file and put it in my local system.

Leave a comment

Your email address will not be published. Required fields are marked *

Similar posts that you may find useful

Adobe campaign tips and tricks
ACC Tips & Tricks, Adobe Campaign, Marketing Automation

Escalate any user rights to admin

1 minute read

Normally web apps run under the web app user (which is anonymous and has very little to zero rights by default) and for certain operations you would need to require to grant additional access, or even grant full admin. To grant full admin for web app user is not solution to go with. Instead I […]

Continue reading
ACC - How to JavaScript in Adobe Campaign Classic
Adobe Campaign, Marketing Automation

Master JavaScript in Adobe Campaign

7 minutes read

Adobe Campaign Classic utilizes JavaScript as the backend language for customizing various aspects of your instance, including workflows, libraries, web applications, and reports. The platform employs the Java Web Server called Tomcat for its operation. To execute JavaScript on the server, Adobe Campaign Classic utilizes a JavaScript engine called SpiderMonkey. SpiderMonkey, developed by the Mozilla […]

Continue reading
The image is a wide-format representation of a modern coding environment, specifically focused on the latest ES6 JavaScript features. It prominently displays a computer screen with a code editor, where JavaScript code is shown with highlights on ES6 features such as arrow functions, classes, and template literals. The code is adorned with vibrant syntax highlighting, making elements like code brackets and semi-colons stand out, emphasizing the JavaScript language. The background is infused with digital and technological elements like binary code patterns and abstract tech-inspired graphics, symbolizing innovation in coding. The overall color scheme is dynamic and lively, reflecting the advanced and cutting-edge nature of ES6 in the realm of web development.
Adobe Campaign, Marketing Automation

Enable newest ES6 JavaScript features

2 minutes read

You may have noticed, when working with the tool for some time, that the JavaScript used around the Adobe Campaign Classic platform is not the newest version. Adobe Campaign Classic relies on ES5 JavaScript, released in 2012. This may cause some first world problems for those accustomed to modern features like Array.indexOf, Array.find, classes, object […]

Continue reading
Salesforce Marketing Cloud Tips
Salesforce Marketing Cloud, SFMC Tips & Tricks

How to add indexes to the data extensions

1 minute read

Maybe the title got you a bit curious because there is no such thing as adding indexes in Salesforce Marketing Cloud data extensions. But what can be done instead? If the indexes cannot be managed by the admins and cannot be requested from support we can try to apply one of the following workarounds. Filtered […]

Continue reading
How to JavaScript in SFMC
Marketing Automation, Salesforce Marketing Cloud

JavaScript in Salesforce Marketing Cloud

3 minutes read

Salesforce Marketing Cloud uses JavaScript where a advanced customization is needed e.g. automations, cloud pages and even in message personalization. Last time we discussed how to JavaScript in Adobe Campaign, we discovered that it utilizes an older version of ECMAScript. However, it’s worth noting that Salesforce Marketing Cloud (SFMC) goes even further back and employs […]

Continue reading