Filename in Documentum REST Services

If you have used Document REST Services you most likely have realized that downloading any content from an object return a “document”/”response” + dot + file extension.

You can check William Zhou’s answer here:

This had been discussed in the initial implementation but hadn’t been implemented since Content-Disposition response header is neither mandatory nor handled by all HTTP clients. Besides, it has some overhead to map the format/mime to a filename extension. But I think it has values helping for the download experience. It is appreciated if you can file a feature request CR so that we can discuss this with the product manager.

I’ve alredy raised a SR to support in order to get OpenText to consider adding this “feature”.

However, if you can’t/don’t want to wait, just “extend” com.emc.documentum.rest.controller.ContentMediaController adding the following line to the getContent method just before returning the response:

headers.setContentDispositionFormData("attachment", (String)co.getAttributeByName("object_name"));

and you’re good to go.

 

One thought on “Filename in Documentum REST Services

  1. Using object name as file name seems not to be a good idea – we constantly facing with following challenges:
    * sometime customers want to generate object names according to other business data
    * in many cases 255 bytes are not enough for file names – so, most our object names do not contain extension part

    and I implemented following algorithm:

    private static String makeValidName(String fileName) {
        StringBuilder nameBuilder = new StringBuilder(fileName.length());
        for (char c : fileName.toCharArray()) {
            if (DfFile.isValidCharForFileName(c)) {
                nameBuilder.append(c);
            }
        }
        return nameBuilder.toString();
    }
    
    public static String makeFileName(String objectName, String extension) {
        objectName = makeValidName(objectName);
        if (StringUtils.isNotBlank(extension)) {
            if (!extension.startsWith(".")) {
                extension = "." + extension;
            }
        }
    
        int maxLength = 255;
        if (StringUtils.isNotBlank(extension)) {
            maxLength -= extension.length();
        }
    
        StringBuilder nameBuilder = new StringBuilder();
    
        int end = objectName.length();
        if (StringUtils.isNotBlank(extension)) {
            if (StringUtils.endsWithIgnoreCase(objectName, extension)) {
                end -= extension.length();
            }
        }
    
        if (StringUtils.isNotBlank(objectName)) {
            for (int i = 0; i < Math.min(end, maxLength); i++) {
                nameBuilder.append(objectName.charAt(i));
            }
        }
    
        if (nameBuilder.length() == 0) {
            nameBuilder.append("content");
        }
        if (StringUtils.isNotBlank(extension)) {
            nameBuilder.append(extension);
        }
        return nameBuilder.toString();
    }
    

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s