thecreation
thecreation

Reputation: 11

Laravel File Storage How to store (decoded) base64 image in Other location

How to store base64 image in other storage location.

By default image store in storage/app folder.

For example:-

$request->base64_image //base64 encoded
$data = substr($request->base64_image, strpos($request->base64_image, ',') + 1);
$data = base64_decode($data);
Storage::disk('local')->put("test.png", $data);

But I have save image on other location.

$request->base64_image //base64 encoded
$data = substr($request->base64_image, strpos($request->base64_image, ',') + 1);
$data = base64_decode($data);
Storage::disk('newfolder')->put("test.png", $data);

config/filesystems.php

  'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

    'newfolder' => [
        'driver' => 'local',
        'root' => storage_path('app/newfolder'),
    ],

],

How to change image storage path using filesystem.

Thanks in advance.

Upvotes: 0

Views: 978

Answers (1)

Muhammad Shariq
Muhammad Shariq

Reputation: 164

Storage::disk is used to specify which device to use as store for your files. You can use remote or local device (other options are are also available). To store file in different location you can simple put path before the file name. For example to put file in newFoler inside storage you can use Storage::put('/newFoler/filename-goes-here.ext', $data)

Upvotes: 1

Related Questions