Feature #67111

eID=dumpFile - support $asDownload and $alternativeFilename through GPVars

Added by Vitoandre D'Oria about 6 years ago. Updated 21 days ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
File Abstraction Layer (FAL)
Start date:
2015-05-22
Due date:
% Done:

100%

Estimated time:
PHP Version:
5.3
Tags:
Complexity:
medium
Sprint Focus:

Description

It would be nice if the eID call would support the properties $asDownload and $alternativeFilename like \TYPO3\CMS\Core\Resource::ResourceStorage::dumpFileContents() does. That way we could use a standardized file processor with basic(hmac)/advanced(through hook) validation.

Optional (but nice to have):
Furthermore it would be nice to get the FLOW f:security.csrfToken() viewHelper to build the token or even better get a <a> tag based downloadViewHelper that does the whole stuff.
This viewHelper would ideally have a $asUri property for inline notations e.g. in data attributes and of course the universal tags.

#1

Updated by Frans Saris about 6 years ago

  • Status changed from New to Accepted
  • Target version changed from 6.2.13 to 7 LTS

That would indeed be a nice feature.

We currently handled it like this https://github.com/beechit/fal_securedownload/blob/master/Classes/Hooks/FileDumpHook.php#L103 but it would better fit in the core.

As this is a feature I set the target to TYPO3 7.

#2

Updated by Vitoandre D'Oria about 6 years ago

Nice! I saw your? code yesterday after discovering the eID=dumpFile and made somethings based on it to test the "download":

<?php
namespace WIRO\WiroBase\ViewHelpers;

 /**
  * DownloadViewHelper
  */
class DownloadViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {

    /**
     * @var string
     */
    protected $tagName = 'a';

    /**
     * Arguments Initialization
     *
     * @return void
     * @see http://docs.typo3.org/typo3cms/ExtbaseFluidBook/8-Fluid/8-developing-a-custom-viewhelper.html#creating-xml-tags-using-tagbasedviewhelper
     */
    public function initializeArguments() {
        $this->registerUniversalTagAttributes();
    }

    /**
     * Generates a secured download link (unlike getPublicUrl this will always result in a download)
     *
     * Usage:
     * <code>
     *     {namespace wiroBase=WIRO\WiroBase\ViewHelpers}
     *
     *     <wiroBase:download resourceObject="{model.file.originalResource.originalFile}" title="Download" class="myDownload">
     *      <div>...</div>
     *     </wiroBase:download>
     *
     *     <a data-download="{wiroBase:download(resourceObject: '{model.file.originalResource.originalFile}', asUri: 1)}">
     *      <div>...</div>
     * </a>
     * </code>
     *
     * @param TYPO3\CMS\Core\Resource\FileInterface $resourceObject File or ProcessedFile
     * @param bool $absolute If set, the URI of the rendered link is absolute
     * @param bool $asUri Return a URI instead <a> tags
     * @return string Rendered link
     * @see \TYPO3\CMS\Core\Resource\ResourceStorage::getPublicUrl()
     */
    public function render(\TYPO3\CMS\Core\Resource\FileInterface $resourceObject, $absolute = FALSE, $asUri = FALSE) {

        $queryParameterArray = array('eID' => 'dumpFile', 't' => '');
        if ($resourceObject instanceof \TYPO3\CMS\Core\Resource\File) {
            $queryParameterArray['f'] = $resourceObject->getUid();
            $queryParameterArray['t'] = 'f';
        } elseif ($resourceObject instanceof \TYPO3\CMS\Core\Resource\ProcessedFile) {
            $queryParameterArray['p'] = $resourceObject->getUid();
            $queryParameterArray['t'] = 'p';
        }

        $queryParameterArray['token'] = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(
            implode('|', $queryParameterArray),
            'resourceStorageDumpFile'
        );

        $uriBuilder = $this->controllerContext->getUriBuilder();
        $uri = $uriBuilder
            ->reset()
            ->setArguments($queryParameterArray)
            ->setCreateAbsoluteUri($absolute)
            ->uriFor();

        if ($asUri) {
            return $uri;
        }

        $this->tag->addAttribute('href', $uri);
        $this->tag->setContent($this->renderChildren());
        $this->tag->forceClosingTag(TRUE);
        return $this->tag->render();
    }
}

The differences are:

  • uriBuilder instead http_build_query/TSFE->absRefPrefix
  • <a> tag based viewHelper instead External because of the universal tags title, class

The code above still requires the $asDownload Parameter.

A alternative could be to introduce a new path like file.originalResource.publicUrl but instead that file.originalResource.downloadUrl (or publicDownloadUrl). It might not be as flexible as the viewHelper but the usage would be similar at least and it could be used in different contexts (BE,FE)

I am not too familiar with getPublicUrl() does it by default return a absolute or relative URI?

The new function might look like this?:

\TYPO3\CMS\Core\Resource\ResourceStorage::getDownloadUrl(ResourceInterface $resourceObject, $absolute = FALSE)

Questions:

  • What should the function return in BE Context if $absolute is set? The url in domain record? Should it work like getPublicUrls: $relativeToCurrentScript = FALSE ? At least in FE context i don't see a need for this??

The second approach is probably more complex because of the different TYPO3_MODE's.

#3

Updated by Benni Mack over 5 years ago

  • Target version changed from 7 LTS to 8 LTS
#4

Updated by Riccardo De Contardi over 4 years ago

  • Target version changed from 8 LTS to 9.0
#5

Updated by Susanne Moog over 3 years ago

  • Category changed from Frontend to File Abstraction Layer (FAL)
  • Target version changed from 9.0 to 9 LTS
#6

Updated by Susanne Moog almost 3 years ago

  • Target version changed from 9 LTS to Candidate for Major Version
#7

Updated by Gerrit Code Review 5 months ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67434

#8

Updated by Gerrit Code Review 29 days ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#9

Updated by Gerrit Code Review 29 days ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#10

Updated by Gerrit Code Review 29 days ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#11

Updated by Gerrit Code Review 29 days ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#12

Updated by Gerrit Code Review 29 days ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#13

Updated by Gerrit Code Review 29 days ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#14

Updated by Gerrit Code Review 28 days ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#15

Updated by Gerrit Code Review 28 days ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#16

Updated by Gerrit Code Review 28 days ago

Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#17

Updated by Gerrit Code Review 28 days ago

Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#18

Updated by Gerrit Code Review 26 days ago

Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#19

Updated by Gerrit Code Review 26 days ago

Patch set 16 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66084

#20

Updated by Christian Eßl 21 days ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF