2

Hello i has upload my file using laravel5, https://github.com/GrahamCampbell/Laravel-Dropbox integrate to dropbox and has succeed, and then i want to get the url for my imgsrc="" on the frontend, How i can get thats url?

dd(Flysystem::get('avatars/kenshin.jpg'));

enter image description here

Where is the url for imgsrc?

Donny Gunawan
  • 363
  • 1
  • 6
  • 21
  • I don't know anything about Flysystem/Laravel, but it looks like it uses the Dropbox PHP SDK, so you probably could use `createShareableLink` or `createTemporaryDirectLink` as listed here: https://github.com/GrahamCampbell/Laravel-Dropbox/blob/master/src/DropboxManager.php Dropbox docs here: https://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/class-Dropbox.Client.html#_createShareableLink https://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/class-Dropbox.Client.html#_createTemporaryDirectLink – Greg Oct 05 '15 at 16:47

4 Answers4

1

Assuming you already created a service provider for custom filesystem.

If you don't know how to do that the doc is Here

Route::get('/dropbox',function()
{
  $filename = '/text1.txt';
  $adapter = \Storage::disk('dropbox')->getAdapter();
  $client = $adapter->getClient();
  $link = $client->createTemporaryDirectLink($filename);
  return <<<EOT
    <a href="{$link[0]}">Link</a>
  EOT;
});

PLEASE NOTE THAT you have to prefix a "\" slash on the filename or else it will thrown an exception.

Voj
  • 51
  • 1
  • 11
1

I save a shared link while saving a new resource. Like so

$path = Storage::disk('dropbox')->putFile('/images', storage_path('images/' . $imageName));

$adapter = \Storage::disk('dropbox')->getDriver()->getAdapter();

$client = $adapter->getClient();

$link = $client->createSharedLinkWithSettings($path);

$newsdigest = NewsDigest::create($request->all('title','type','source', 'article') + [

    'reading_attachment' => $link['url']

]);
Matt Ke
  • 3,599
  • 12
  • 30
  • 49
0

Create another route for a method in your controller and pass the file name that you want to access from dropbox with the route. Use getFile() method in your controller and pass the filename to the variable.

public function getFile($file_name)
{
    $client = new Client('dropbox.token','dropbox.appName');
    $this->filesystem = new Filesystem(new Dropbox($client, '/path'));

    try{
        $file = $this->filesystem->read($file_name);
    }catch (\Dropbox\Exception $e){
        return Response::json("{'message' => 'File not found'}", 404);
    }

    $response = Response::make($file, 200);

    return $response;

}
Chandresh
  • 1
  • 1
  • 1
0

The best way I found to upload your file in Dropbox and even get share files link in your PHP or Laravel or any PHP framework is by using this package

composer require kunalvarma05/dropbox-php-sdk

This is how to use it, an example I made using Laravel:

(An illustrative image)

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • 1
    Please don’t place screenshots of code inline. That makes it difficult for readers to copy and paste the solution. Can you edit your answer to include the code in the markdown? – Jeremy Caney May 19 '20 at 19:05