New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Control Panel Form Submission File Download Links

Taylor Collins February 25, 2019 by Taylor Collins

Since nobody commented on my original post, nor did the folks at Statamic respond to my support request, I'm editing my post to make the issues I posted, and the respective solutions I came up with, more clear.

Issue #1: When viewing a form submission in the cp, the links to download any uploaded files target the actual URL of the file, as opposed to the cp's download route. This is important because if your files are hosted on S3 and don't have a public bucket policy, you won't be able to download them.

Solution to Issue #1: I added the following javascript to site/helpers/cp/script.js which changes the href of the links to use the cp's download route:

/**
 * Change AWS file download links in tables to use the control panel's
 * download route as opposed to the direct file url.
 */
document.querySelectorAll('table.dossier a').forEach(function(link) {
  link.onclick = function() {
    if (this.href.indexOf('amazonaws.com') != -1) {
      var parts = this.getAttribute('href').split('/');
      var container = parts[ parts.length - 2 ];
      var filename = parts[ parts.length - 1 ];
      this.href = '/cp/assets/download/' + container + '/' + filename;
    }
  }
});

Issue #2: The uploaded file names are simply imploded together with no separator: file1.pdffile2.pdffile3.pdf

Solution to Issue #2: I added the following styles to site/helpers/cp/override.css

/* Make uploaded files appear on individual lines */
table.dossier td a + a {
    display: block;
}
Answered by Taylor Collins!
>>>>>>> Answered <<<<<<<
3 Replies
1 Follower