Comments

gokulnk created an issue. See original summary.

swim’s picture

Are you exporting to your private file schema while having not defined a private schema yet?

swim’s picture

Status: Active » Closed (works as designed)

Please reopen if you are still having issues.

Alex Andrascu’s picture

Status: Closed (works as designed) » Needs review
StatusFileSize
new1.22 KB

This is indeed happening using default settings with Path set to public://backup_db

Attached patch fixes it.

Alex Andrascu’s picture

StatusFileSize
new714 bytes

Oops .module file added to patch by mistake. Patch re-attached.

swim’s picture

Legend, thanks for reporting / looking at this. Could you perform one additional check please? Could you test this patch with the private:// schema? We might need another condition based on the schema type.

Alex Andrascu’s picture

True, it now breaks the private schema. I'll be looking into it some point this week .

Alex Andrascu’s picture

Status: Needs review » Needs work
Alex Andrascu’s picture

Also if you have some spare time you can experiment with this.

Move the url logic to .module like so:

use Drupal\Core\Url;

... etc etc

/**
 * file_create_url in combination with Url::fromUri does
 * not return a correct path for private files.
 */
function backup_db_link($uri) {
  $scheme = \Drupal::service('file_system')->uriScheme($uri);
  $path = Url::fromUri(file_create_url($uri));
  return $path;
}

change the controller historyOverview like so:

foreach ($results as $result) {
      $url = backup_db_link($result->uri);

      $location = \Drupal::l($result->uri, $url);
      $created = \Drupal::service('date.formatter')->format($result->created, 'html_date');

      $rows[$result->fid] = array(
        'fid' => $result->fid,
        'name' => $result->name,
        'location' => $location,
        'created' => $created
      );
    }

It will now generate the correct download links but you'll get an access denied if you try downloading the private one.
I don't have enough time to commit to it at the moment but if you do I think we're on to something here. Otherwise I'll pick it up later.

osman’s picture

StatusFileSize
new1.38 KB

Here's a patch based on Alex's suggestion from #9.

However, since <?php Url::fromUri(file_create_url($uri)) ?> actually works for both `public` and `private` schemes, and it hasn't been used anywhere else I removed the <?php backup_db_link() ?> function.

I tested with both schemes, links are generated correctly.

I too get access denied error for private file download requests though.

osman’s picture

Status: Needs work » Needs review
osman’s picture

btw, I tried Private files download permission module to bypass access issues.

It seems that it can enable private file downloads without compromising access rules for rest of the private files:

Permissions

Access configuration