Jump to content

To get shared link to the file uploaded to dropbox with Laravel


mstdmstdd

Recommended Posts

Hello,
In laravel 5.5 application I need to upload file to dropbox and get shared link to this file.

I used DropboxAdapter library and this doc https://murze.be/dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application
And looking at this doc
https://laravel.com/docs/5.5/filesystem#retrieving-files

I managed to put a file to dropbox storage ok, but failed to get its url.
I did like :

$exists = Storage::disk('dropbox')->exists($dest_dropbox_file_name);
echo '<pre>$exists::'.print_r($exists,true).'</pre>'; // Value is 1

$url = Storage::disk('dropbox')->url($dest_dropbox_file_name);
echo '<pre>$url::'.print_r($url,true).'</pre>';

I got error:

RuntimeException
This driver does not support retrieving URLs.


Which is the right way to get shared url of uploaded filr to dropbox?
Who used this library ?

Thanks!

Link to comment
Share on other sites

Yes, I run composer update and followed this article and in my model:



<?php


namespace App;


use Illuminate\Database\Eloquent\Model;
use Auth;
use Intervention\Image\Facades\Image as Image;
use Carbon\Carbon;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;


use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client;
use Spatie\FlysystemDropbox\DropboxAdapter;




...
class TmpCsvp extends MyAppModel
{


    ...
    public static function setToIsApplied($id,bool $to_copy, $to_employee_id)
    {
        ...
            $dropboxClient = new Client(env('DROPBOX_OATH'));
            $adapter = new DropboxAdapter($dropboxClient);
            $filesystem = new Filesystem($adapter);




            echo '<pre>$filesystem::'.print_r($filesystem,true).'</pre>';   // The output is League\Flysystem\Filesystem Object class
            echo '<pre>$dropboxClient::'.print_r($dropboxClient,true).'</pre>'; //  The output is Spatie\Dropbox\Client Object


            $uploaded = $filesystem->put($dest_dropbox_file_name, $file, []);
            echo '<pre>$uploaded::'.print_r($uploaded,true).'</pre>';   // The output is 1


            $exists = Storage::disk('dropbox')->exists($dest_dropbox_file_name);
            echo '<pre>$exists::'.print_r($exists,true).'</pre>';


            $url = Storage::disk('dropbox')->url($dest_dropbox_file_name);  // THAT LINE RAISE EXCEPTION
            echo '<pre>$url::'.print_r($url,true).'</pre>';


That is error page output: https://imgur.com/a/HpE4M

But file was uploaded to the directory/filename in $dest_dropbox_file_name like “docs/-doc-130/lender_image_1.jpg”

 

My composer.json :



{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "doctrine/dbal": "^2.5",
        "fideloper/proxy": "~3.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "maatwebsite/excel": "~2.1.0",
        "mcamara/laravel-localization": "^1.3",
        "rcrowe/twigbridge": "^0.9.5",
        "sebastiansulinski/dotenv": "^2.0",
        "sebastiansulinski/php-backup": "^2.0",
        "spatie/flysystem-dropbox": "^1.0",
        "spatie/laravel-backup": "^3.0.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}


What wrong in my configuraion/code?

 

Thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Hello,
I still search for a decision, as I still have an error:

This driver does not support retrieving URLs.

when I try to get shared url of uploaded file.

I created a small application, repeating the error I have.
Public url:
https://www.dropbox.com/s/rmclue63tyeyu1w/dropbox_demo.zip?dl=0


Under http://127.0.0.1:8000/ url there is “Run drop box” menu item and clicking on it the routing would be run.
I output to the console all related variables.

I hardcoded app's key/secret in the HomeController.php and in the config/app.php files.
If there is no error in the code,
please, try to run under your dropbox creditials. Could it be misconfiguration on dropbox side of my account?


Thank you for your time!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.