Project

General

Profile

Actions

Feature #67111

closed

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

Added by Vitoandre D'Oria almost 9 years ago. Updated over 2 years ago.

Status:
Closed
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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #83285: Support HTML5 "download" attribute in linksClosed2017-12-01

Actions
Actions #1

Updated by Frans Saris almost 9 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.

Actions #2

Updated by Vitoandre D'Oria almost 9 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.

Actions #3

Updated by Benni Mack over 8 years ago

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

Updated by Riccardo De Contardi about 7 years ago

  • Target version changed from 8 LTS to 9.0
Actions #5

Updated by Susanne Moog about 6 years ago

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

Updated by Susanne Moog over 5 years ago

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

Updated by Gerrit Code Review over 3 years 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

Actions #8

Updated by Gerrit Code Review almost 3 years 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

Actions #9

Updated by Gerrit Code Review almost 3 years 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

Actions #10

Updated by Gerrit Code Review almost 3 years 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

Actions #11

Updated by Gerrit Code Review almost 3 years 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

Actions #12

Updated by Gerrit Code Review almost 3 years 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

Actions #13

Updated by Gerrit Code Review almost 3 years 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

Actions #14

Updated by Gerrit Code Review almost 3 years 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

Actions #15

Updated by Gerrit Code Review almost 3 years 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

Actions #16

Updated by Gerrit Code Review almost 3 years 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

Actions #17

Updated by Gerrit Code Review almost 3 years 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

Actions #18

Updated by Gerrit Code Review almost 3 years 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

Actions #19

Updated by Gerrit Code Review almost 3 years 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

Actions #20

Updated by Christian Eßl almost 3 years ago

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

Updated by Oliver Bartsch over 2 years ago

  • Status changed from Resolved to Closed
Actions #22

Updated by Oliver Bartsch over 2 years ago

  • Related to Feature #83285: Support HTML5 "download" attribute in links added
Actions

Also available in: Atom PDF