(Unsolved bug) This driver does not support creating temporary URLs

What seems to be the problem:

My application was running perfectly passing each test and running in the browser.

After upgrading my application according to this screencast:

https://laravel-livewire.com/screencasts/s6-bind-to-models

Especially the “type-hinting” at 1:42 (which made me upgrade my php version from 7.3 to 7.4 inside my composer.json (after I ran composer update and composer install)) (I did that because it was suggested by php storm) - no idea what the result is of upgrading php inside the composer.json file and than runnin update and install … I did it anyways because … why not? php storm will know what to do

  "php": "^7.3|^8.0",   ->    to "php": "^7.4",

I am now getting the error:

This driver does not support creating temporary URLs.

Now I went back to my last commit where everything used to work and things still blow up.

I mean I also revered to the original

  "php": "^7.3|^8.0",   ->    to "php": "^7.4",

So something must have gone crazy in the “userland” I guess.

Other people are experiencing similar issues.

https://github.com/livewire/livewire/issues/1106

Does anyone have an idea where to start?

Steps to Reproduce:

Just follow the screencast or check my code examples below

Are you using the latest version of Livewire:

Yes.

Do you have any screenshots or code examples:

this is my livewire “profile.blade.php” if I remove the temporaryUrl method the test passes and the browser works.

               <x-input.filepond wire:model="files" multiple/>

                <div >
                    @foreach($files as $file)
                        <img src="{{ $file->temporaryUrl() }}">
                    @endforeach
                </div >

this is my livewire model “profile.php”

<?php

namespace App\Http\Livewire;

use App\Models\User;
use Livewire\Component;
use Livewire\WithFileUploads;

class Profile extends Component
{
//    protected $listeners = ['notify-saved'];
    use WithFileUploads;

    public User $user;

    public $upload;

    public $files = [];

    protected $rules = [
        'user.about' => 'max:140|nullable',
        'upload' => 'image|max:20000|nullable'
    ];

    public function mount()
    {
        $this->user = auth()->user();
    }

    public function updatedAbout()
    {
        $this->validateOnly('about');
    }

    public function updatedNewAvatar()
    {
        $this->validate([
            'upload' => 'image|max:20000'
        ]);
    }

    public function save()
    {
        $this->validate();

        $this->user->save();

        $this->upload && $this->user->update([
           'avatar' => $this->upload->store('/', 'avatars'),
       ]);

        $this->emitSelf('notify-saved');
    }
}

This is my test

 /** @test */
    public function can_upload_avatar()
    {
        $user = User::factory()->create();

        $file = UploadedFile::fake()->image('photo1.jpg');

        Storage::fake('avatars');

        Livewire::actingAs($user)
            ->test('profile')
            ->set('upload', $file)
            ->call('save');

        $user->refresh();

        $this->assertNotNull($user->avatar);
            Storage::disk('avatars')->assertExists($user->avatar);
    }

and the results:

this is my disk

'disks' => [

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

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

this is my livewire config


    'temporary_file_upload' => [
        'disk' => null,        // Example: 'local', 's3'              Default: 'default'
        'rules' => null,       // Example: ['file', 'mimes:png,jpg']  Default: ['required', 'file', 'max:12288'] (12MB)
        'directory' => null,   // Example: 'tmp'                      Default  'livewire-tmp'
        'middleware' => null,  // Example: 'throttle:5,1'             Default: 'throttle:60,1'
        'preview_mimes' => [   // Supported file types for temporary pre-signed file URLs.
            'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
            'mov', 'avi', 'wmv', 'mp3', 'm4a',
            'jpeg', 'mpga', 'webp', 'wma'
        ],
    ],

this is my composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "7.4",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.12",
        "laravel/tinker": "^2.5",
        "livewire/livewire": "^2.3"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}


WHILE WRITING THIS ARTICLE I FOUND THE FOLLOWING

I believe that only S3 can do temporary URLs - if your driver is local, then you get no joy from that method (at least if I’m remembering my past projects correctly). I think it’s a Laravel issue, and not a LiveWire issue in this case.

Hey, @reniar1
I’m not sure but you can take a look at this solution it may help you or gives you an idea

No wit is getting really strange:

When I change my test to *.png than it passes:

/** @test */
    public function can_upload_avatar()
    {
        $user = User::factory()->create();

        $file = UploadedFile::fake()->image('photo); 1**.png** <_--_--<_--_--<_--_--<_--_--

        Storage::fake('avatars');

        Livewire::actingAs($user)
            ->test('profile')
            ->set('upload', $file)
            ->call('save');

        $user->refresh();

        $this->assertNotNull($user->avatar);
            Storage::disk('avatars')->assertExists($user->avatar);
    }

But *.jpg used to work before no matter what, now I also get the same error when I upload *pdf or anything really …

It is even getting more weird now and the temporaryURL() shown images are all out of line and they appear to have a padding bottom or something but obviously they don’t have that …

<x-input.group label="Avatar" for="avatar" :error="$errors->first('upload')">
                    <x-input.file-upload wire:model="upload" id="avatar">
                        <span class="mr-2 inline-block h-12 w-12 rounded-full overflow-hidden bg-gray-100">
                            @if($upload)
                                <img src="{{ $upload->temporaryUrl() }}">
                            @else
                                <img src="{{ auth()->user()->avatarUrl() }}">
                            @endif
                        </span >
                    </x-input.file-upload >
                </x-input.group >

Screenshot 2020-12-01 at 10.48.02

Also with the help of the community i figured out the the validation for *.jpg failed, because it was not llisted in the livewire config file, but still *.jpg and *jpeg fail in the

validation when save() method is invoked

Okay this is 100% a bug in laravel or livewire that is really hughe because it makes validation for uploads impossible if you don’t hack the framework or in some other way declare proper validation rules for uploaded items … on top of that it is buggy in rendering the uploaded previews. Some temporary uploads have a strange spacing under them

I have the same issue using:

livewire/livewire v2.3.5
laravel/framework v8.17.1
PHP 7.4.12

I can’t resolve it, is this an issue?


Works!!! :slight_smile:

1 Like