nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.34k stars 4.06k forks source link

[Bug]: getDirectDownload() returns empty array #32438

Closed SpechtD closed 1 year ago

SpechtD commented 2 years ago

⚠️ This issue respects the following points: ⚠️

Bug description

IStorage::getDirectDownload() always returns an empty array in the code under Steps to reproduce.

Steps to reproduce

/** @var File*/
private $file;

/** @var Folder */
private $userFolder;

/** @var IStorage */
private $storage;

public function __construct(string $path, string $userID, IRootFolder $iRootFolder)
{
    $this->userFolder = $iRootFolder->getUserFolder($userID);
    $this->file = $this->userFolder->get($path);
    $this->storage = $this->file->getStorage();
}

public function generateUrl()
{
    $filePath = $this->file->getInternalPath();
    $url = $this->storage->getDirectDownload($filePath);
    return $url;
}

Expected behavior

Return a URL for direct download of a given file.

Installation method

Manual installation

Operating system

Other

PHP engine version

PHP 7.4

Web server

Apache (supported)

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

No response

What user-backends are you using?

Configuration report

No response

List of activated Apps

Enabled:
  - accessibility: 1.10.0
  - bbb: 2.2.0
  - calendar: 3.2.2
  - cloud_federation_api: 1.7.0
  - comments: 1.14.0
  - contacts: 4.1.0
  - contactsinteraction: 1.5.0
  - dashboard: 7.4.0
  - dav: 1.22.0
  - federatedfilesharing: 1.14.0
  - federation: 1.14.0
  - files: 1.19.0
  - files_sharing: 1.16.1
  - files_trashbin: 1.14.0
  - files_versions: 1.17.0
  - lookup_server_connector: 1.12.0
  - mail: 1.11.7
  - oauth2: 1.12.0
  - provisioning_api: 1.14.0
  - settings: 1.6.0
  - sharebymail: 1.14.0
  - spreed: 14.0.0-beta.1
  - systemtags: 1.14.0
  - theming: 1.15.0
  - twofactor_backupcodes: 1.13.0
  - updatenotification: 1.14.0
  - user_status: 1.4.0
  - weather_status: 1.4.0
  - workflowengine: 2.6.0
Disabled:
  - admin_audit
  - bruteforcesettings
  - encryption
  - files_external
  - testing
  - user_ldap

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

No response

kesselb commented 2 years ago

Hey, I think getDirectDownload() is not what you are looking for.

To directly download a file as authenticated user: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#downloading-files

A custom storage implementation can return an url for direct download of a give file.

The idea is/was that a storage implementation (e.g. S3) provide a link (including an access token) to directly download a file from a remote storage.

SpechtD commented 2 years ago

Till now I have used this, but from the frontend.: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#direct-download Now I need to generate the URL in the backend, so I tried using the PHP API.

kesselb commented 2 years ago

https://github.com/nextcloud/server/blob/master/apps/dav/lib/Controller/DirectController.php

I guess you need to copy the above logic for now.

cc @skjnldsv @icewind1991 do you know if we have a php api to generate a direct download link?

sualko commented 2 years ago

I guess it just was forgotten at some point https://github.com/nextcloud/server/blob/459202d54cf891298099c3f793d2b163b9b76541/lib/private/Files/Storage/Common.php#L516-L518

So probably it make sense to implement the method in the Local or Root with the logic from the dav app.

szaimen commented 1 year ago

Hi, please update to 24.0.8 or better 25.0.2 and report back if it fixes the issue. Thank you!