Question on the AEM Assets upload library | Community
Skip to main content
Best answer by kartheekd203042

Here is the update from Adobe:

 

As the DirectBinary does not create(not a bug) the folders and the documentation specifically says the folder must exist - see [1]. The logic to create folders is included in the higher level FileSystemUpload wrapper - see https://github.com/adobe/aem-upload/blob/master/src/filesystem-upload.js#L58. the DirectBinary type is the lowest level upload logic and does not include this kind of additional business logic. The customer should use the wrappers. If you want to create folders you need to use filesystem-upload wrappers.

[0] https://github.com/adobe/aem-upload#:~:text=uploaded.%20Folder%0A//-,must%20already%20exist,-.%0Aconst%20targetUrl

 

We were using the logic since our assets are in Azure containers and DirectBinary was the only option - 

Please find the ticket details below regarding the folder creation when using DirectBinary Approach. ASSETS-48959

We ended up creating the folders using the AEM REST API then invoke the library to upload assets into that folder.

2 replies

giuseppebaglio
Level 10
February 21, 2025

Hi @kartheekd203042

The issue you're encountering with the intermittent 404 error during asset uploads is likely related to timing or synchronization challenges when dynamically creating folders and immediately using them for uploads. This can happen if the folder creation process hasn't fully propagated or completed before the upload begins, even though you're checking for a 200 or 201 response.

 

To address this, I could recommend leveraging the Asset Folder Creator from the ACS Commons package. This tool is specifically designed to help quickly build complex Asset Folder hierarchies in AEM, ensuring that the folders are created efficiently and reliably before any assets are uploaded.

 
  • The Asset Folder Creator allows you to define and create nested folder structures (like /content/dam/tenant/products/hierarchy1/hierarchy2/hierarchy3) in one go, reducing the chances of partial or incomplete folder creation.
  • By using a dedicated tool for folder creation, you can ensure that the folder hierarchy is fully established before initiating the upload process.
  • It’s particularly useful for scenarios where folders need to be created dynamically based on product structures or other hierarchical data.
 
February 21, 2025

Thanks @giuseppebaglio for the quick response.

Do note that this folder creation is happening from an Azure Function being managed by an external team. They are using the REST APIs to do all these operations and using the aem-upload library. I am not sure how ACS can help this use case unless we customize to expose this ACS tool via another custom API? Sorry if I understood it incorrectly but please feel free to chime in.

giuseppebaglio
Level 10
February 24, 2025

hi @kartheekde2If using the ACS tool isn't feasible, you can consider creating the necessary folder structure via API before executing the aem-upload command. This way, you can ensure that the folder hierarchy is fully established before initiating the upload process.

 

Here's an example of a curl command, which can easily be converted into JavaScript code for integration with the aem-upload process:

 

curl -u admin:admin \ -F":name=MyFolder" \ -F"jcr:primaryType=sling:Folder" \ http://localhost:4502/content/dam/folderName

 

 

 
kautuk_sahni
Community Manager
Community Manager
March 4, 2025

@kartheekd203042 Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Kautuk Sahni
kartheekd203042
Level 3
March 5, 2025

I am still working with Adobe on this @kautuk_sahni 

kartheekd203042
kartheekd203042AuthorAccepted solution
Level 3
March 24, 2025

Here is the update from Adobe:

 

As the DirectBinary does not create(not a bug) the folders and the documentation specifically says the folder must exist - see [1]. The logic to create folders is included in the higher level FileSystemUpload wrapper - see https://github.com/adobe/aem-upload/blob/master/src/filesystem-upload.js#L58. the DirectBinary type is the lowest level upload logic and does not include this kind of additional business logic. The customer should use the wrappers. If you want to create folders you need to use filesystem-upload wrappers.

[0] https://github.com/adobe/aem-upload#:~:text=uploaded.%20Folder%0A//-,must%20already%20exist,-.%0Aconst%20targetUrl

 

We were using the logic since our assets are in Azure containers and DirectBinary was the only option - 

Please find the ticket details below regarding the folder creation when using DirectBinary Approach. ASSETS-48959

We ended up creating the folders using the AEM REST API then invoke the library to upload assets into that folder.