serveAsAttachment doesn't work (here: .pdf)

Hi,

I tried to force pdf files as download instead of displaying them inline. So I changed the setting in my config:

settings.assetmanager.types.document.pdf = { serveAsAttachment=true, mimeType="application/pdf" };

Sound’s good, doesn’t work.

During debugging I found this (AssetDownload.cfc$asset (line 123ff)):

        if ( type.trackDownloads ) {
					if ( isFeatureEnabled( "websiteUsers" ) ) {
						websiteUserActionService.recordAction(
							  action     = "download"
							, type       = "asset"
							, userId     = getLoggedInUserId()
							, identifier = assetId
						);
					}
          header name="Content-Disposition" value="attachment; filename=""#filename#""";
				} else {
					header name="Content-Disposition" value="inline; filename=""#filename#""";
				}

The serveAsAttachementsetting is completely ignored, instead the trackDownloads is validated.

This looks wrong to me. The case “yes, I want to force a download, but no, I don’t want to track it” doesn’t exist.

Is there a reason?

An

        if( type.trackDownloads || type.serveAsAttachment ) {

          if( isFeatureEnabled( "websiteUsers" ) && type.trackDownloads ) {

is the right one, I think.

I raised a ticket: PRESIDECMS-3166

Best

Michi

Yeah, defo sounds like a bug, though I’m not sure the suggested fix is correct. Caused by changes in ticket PRESIDECMS-2822 as you point out in your comment.

I’ve linked the tickets and updated the description with a concise repro in PRESIDECMS-3166

A work around for now should be to trick the system by setting trackDownloads=true on the asset type definition.

settings.assetmanager.types.document.pdf = { 
      serveAsAttachment = true
    , trackDownloads    = true
    , mimeType          = "application/pdf"
};
1 Like