We've a requirement to restrict the asset upload based on certain file name pattern on AEMaaCS. We tried using the fileupload.js illegal charset. It is not working. Custom clientlibs with the file upload validation that is also not working on cloud service. OOTB in Cloud we've validation for MIME type but there is not restriction on the file name validation. Can someone help if they've come across such issue and implementation any solution?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Everyone - We should update the list of the chars to be restricted by overlaying this file. /libs/dam/gui/coral/components/admin/clientlibs/damutil/js/util.js.
Hi @PrajwalRe ,
To configure Experience Manager to restrict users to upload files of specific MIME types:
Navigate to Tools > Assets > Assets Configurations.
Click Upload Restrictions.
Click Add to define the allowed MIME types.
Specify the MIME type in the text box. You can click Add again to specify more allowed MIME types. You can also click to delete to delete any MIME type from the list.
Click Save.
Link to check out:
https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/assets/admin/con....
Thanks
Tarun
Thanks @TarunKumar for the reply. We're looking to restrict the file patterns rather than mime types.
HI @PrajwalRe
Create a custom workflow as below and it should work
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import javax.jcr.Session;
@Component(
service = JobConsumer.class,
property = {
JobConsumer.PROPERTY_TOPICS + "=dam/event/asset"
}
)
public class AssetUploadRestrictionService implements JobConsumer {
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Override
public JobResult process(Job job) {
try {
ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
Session session = resourceResolver.adaptTo(Session.class);
String path = (String) job.getProperty("path");
String name = session.getNode(path).getName();
if (!name.matches("your desired pattern")) {
// Move the asset to a quarantine folder or delete it
// session.getNode(path).remove();
// session.save();
}
return JobResult.OK;
} catch (Exception e) {
return JobResult.FAILED;
}
}
}
Hi,
You can follow a similar approach to this: http://experience-aem.blogspot.com/2021/05/aem-cloud-service-configure-file-upload-max-size-per-asse... and update the code to check the name instead of the size of an asset.
Hope this helps
hi @PrajwalRe ,
If you need to restrict asset uploads based on certain file name patterns in Adobe Experience Manager as a Cloud Service (AEMaaCS), you might need to approach this differently since some traditional methods may not work in the cloud environment. Here's a suggestion on how you might achieve this:
Custom Workflow Step: Implement a custom workflow step that checks the file name pattern of assets during the upload process. This custom workflow step can be triggered after the asset is uploaded but before it's persisted in the repository.
Custom Workflow Process Step Implementation: Create a Java class that implements the custom workflow process step. In this class, you can access the uploaded asset and check its file name against the required pattern. If the file name matches the pattern, proceed with the workflow. Otherwise, halt the workflow and reject the asset upload.
Workflow Configuration: Configure the workflow model to include your custom workflow step. This ensures that the custom step is executed whenever an asset is uploaded.
Handling Rejections: Decide how you want to handle rejected uploads. You might want to send notifications to users or log the rejected uploads for review.
Testing: Thoroughly test the custom workflow step to ensure that it correctly identifies assets with the specified file name patterns and rejects uploads as expected.
Here's a basic example of what the custom workflow step implementation might look like:
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.event.jobs.JobProcessor;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
@Component(
service = JobProcessor.class,
property = {
JobProcessor.PROPERTY_TOPICS + "=" + "your/custom/workflow/step/topic"
}
)
public class FileNamePatternValidationStep implements JobProcessor {
@Override
public boolean process(Job job) {
// Extract asset information from the job
String assetPath = (String) job.getProperty("assetPath");
String fileName = (String) job.getProperty("fileName");
// Check if the file name matches the required pattern
if (!isValidFileName(fileName)) {
// Reject the asset upload
// You can log a message or send a notification here
return false;
}
// Proceed with the workflow
// You can perform additional actions here if needed
return true;
}
private boolean isValidFileName(String fileName) {
// Implement logic to check if the file name matches the required pattern
// Return true if the file name is valid, false otherwise
}
}
In this example, FileNamePatternValidationStep is a custom workflow step that implements the JobProcessor interface. It checks the file name of the uploaded asset against a specified pattern and rejects the upload if the file name does not match the pattern.
Remember to deploy and configure the custom workflow step properly in your AEMaaCS environment. Additionally, ensure that the necessary permissions are set up to execute the custom workflow step.
Everyone - We should update the list of the chars to be restricted by overlaying this file. /libs/dam/gui/coral/components/admin/clientlibs/damutil/js/util.js.
Views
Likes
Replies