-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Server specifications
- PHP
7.1.11
- Node
v8.9.1
- Laravel
5.5.26
- OS:
Debian GNU/Linux 8.9 (jessie)
as π³ Docker container - Browser: Firefox Developer Edition
58.0b11
- Dependencies βοΈ all installed
Preface
Hello everyone
I'm trying to understand what's going on with this bug since it popped out of nowhere this afternoon π
Let me explain:
Problem
Whenever I try to define a conversion inside the User
model like this:
/**
* @param \Spatie\MediaLibrary\Media|null $media
* @throws \Spatie\Image\Exceptions\InvalidManipulation
*/
public function registerMediaConversions(Media $media = null)
{
$this->addMediaConversion("square_96")
->crop(Manipulations::CROP_CENTER, 96,96)
->performOnCollections("photos");
}
And upload a photo using the method provided (inside the User.php):
/**
* @param \Illuminate\Http\UploadedFile $uploadedPhoto
* @return \Spatie\MediaLibrary\Media
* @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded
*/
public function uploadPhoto(UploadedFile $uploadedPhoto)
{
return $this->addMedia($uploadedPhoto)
->toMediaCollection("photos");
}
The current exception that it throws is a bogus Array to string conversion
that comes directly from symfony's Process.php
file, here is the stack trace
"message": "Array to string conversion",
"exception": "ErrorException",
"file": "/app/vendor/symfony/process/Process.php",
"line": 335,
"trace": [
{
"function": "handleError",
"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
"type": "->"
},
{
"file": "/app/vendor/symfony/process/Process.php",
"line": 335,
"function": "proc_open"
},
{
"file": "/app/vendor/symfony/process/Process.php",
"line": 210,
"function": "start",
"class": "Symfony\\Component\\Process\\Process",
"type": "->"
},
{
"file": "/app/vendor/spatie/image-optimizer/src/OptimizerChain.php",
"line": 101,
"function": "run",
"class": "Symfony\\Component\\Process\\Process",
"type": "->"
},
{
"file": "/app/vendor/spatie/image-optimizer/src/OptimizerChain.php",
"line": 77,
"function": "applyOptimizer",
"class": "Spatie\\ImageOptimizer\\OptimizerChain",
"type": "->"
},
{
"file": "/app/vendor/spatie/image/src/Image.php",
"line": 139,
"function": "optimize",
"class": "Spatie\\ImageOptimizer\\OptimizerChain",
"type": "->"
},
{
"file": "/app/vendor/spatie/image/src/Image.php",
"line": 118,
"function": "performOptimization",
"class": "Spatie\\Image\\Image",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileManipulator.php",
"line": 117,
"function": "save",
"class": "Spatie\\Image\\Image",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileManipulator.php",
"line": 84,
"function": "performConversion",
"class": "Spatie\\MediaLibrary\\FileManipulator",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Support/Collection.php",
"line": 337,
"function": "Spatie\\MediaLibrary\\{closure}",
"class": "Spatie\\MediaLibrary\\FileManipulator",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileManipulator.php",
"line": 95,
"function": "each",
"class": "Illuminate\\Support\\Collection",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/Jobs/PerformConversions.php",
"line": 32,
"function": "performConversions",
"class": "Spatie\\MediaLibrary\\FileManipulator",
"type": "->"
},
{
"function": "handle",
"class": "Spatie\\MediaLibrary\\Jobs\\PerformConversions",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
"line": 29,
"function": "call_user_func_array"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
"line": 87,
"function": "Illuminate\\Container\\{closure}",
"class": "Illuminate\\Container\\BoundMethod",
"type": "::"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
"line": 31,
"function": "callBoundMethod",
"class": "Illuminate\\Container\\BoundMethod",
"type": "::"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Container/Container.php",
"line": 549,
"function": "call",
"class": "Illuminate\\Container\\BoundMethod",
"type": "::"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
"line": 94,
"function": "call",
"class": "Illuminate\\Container\\Container",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 114,
"function": "Illuminate\\Bus\\{closure}",
"class": "Illuminate\\Bus\\Dispatcher",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 102,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
"line": 98,
"function": "then",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php",
"line": 49,
"function": "dispatchNow",
"class": "Illuminate\\Bus\\Dispatcher",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php",
"line": 76,
"function": "call",
"class": "Illuminate\\Queue\\CallQueuedHandler",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php",
"line": 42,
"function": "fire",
"class": "Illuminate\\Queue\\Jobs\\Job",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
"line": 184,
"function": "push",
"class": "Illuminate\\Queue\\SyncQueue",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
"line": 160,
"function": "pushCommandToQueue",
"class": "Illuminate\\Bus\\Dispatcher",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
"line": 73,
"function": "dispatchToQueue",
"class": "Illuminate\\Bus\\Dispatcher",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileManipulator.php",
"line": 130,
"function": "dispatch",
"class": "Illuminate\\Bus\\Dispatcher",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileManipulator.php",
"line": 45,
"function": "dispatchQueuedConversions",
"class": "Spatie\\MediaLibrary\\FileManipulator",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/Filesystem/DefaultFilesystem.php",
"line": 34,
"function": "createDerivedFiles",
"class": "Spatie\\MediaLibrary\\FileManipulator",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileAdder/FileAdder.php",
"line": 365,
"function": "add",
"class": "Spatie\\MediaLibrary\\Filesystem\\DefaultFilesystem",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileAdder/FileAdder.php",
"line": 353,
"function": "processMediaItem",
"class": "Spatie\\MediaLibrary\\FileAdder\\FileAdder",
"type": "->"
},
{
"file": "/app/vendor/spatie/laravel-medialibrary/src/FileAdder/FileAdder.php",
"line": 285,
"function": "attachMedia",
"class": "Spatie\\MediaLibrary\\FileAdder\\FileAdder",
"type": "->"
},
{
"file": "/app/Entities/User.php",
"line": 170,
"function": "toMediaCollection",
"class": "Spatie\\MediaLibrary\\FileAdder\\FileAdder",
"type": "->"
},
{
"file": "/app/Http/Controllers/Admin/PhotoController.php",
"line": 36,
"function": "uploadPhoto",
"class": "App\\Entities\\User",
"type": "->"
},
{
"function": "upload",
"class": "App\\Http\\Controllers\\Admin\\PhotoController",
"type": "->"
}
]
}
Additional Resources
Tests
The weird part of all this is that the test works like a charm, the current feature test is something like this
/** @test */
public function it_uploads_a_new_photo()
{
Storage::fake("tmp");
$response = $this->post("dashboard/photos/{$this->user->uuid}/upload", [
"photo" => UploadedFile::fake()->image("fake_photo.png"),
]);
$response->assertStatus(Response::HTTP_OK);
$photo = $response->getOriginalContent()["photo"];
Storage::disk("media")->assertExists("{$photo->uuid}/fake_photo.png");
Storage::disk("media")->assertExists("{$photo->uuid}/conversions");
Storage::disk("media")->assertExists("{$photo->uuid}/conversions/square_96.jpg");
}
As soon as I cut the media conversion code from registerMediaConversions
the upload system works normally but, of course, no conversion files are added.
Config Customization
The only thing that I've customize inside the config/medialibrary.php
file is the custom_path_generator_class
which points on a simple class that implements the given interface
final class MediaPathGeneration implements PathGenerator
{
/*
* Get the path for the given media, relative to the root storage path.
*/
public function getPathForConversions(Media $media) : string
{
return $this->getPath($media) . "conversions/";
}
/*
* Get the path for conversions of the given media, relative to the root storage path.
* @return string
*/
public function getPath(Media $media) : string
{
return "{$media->uuid}/";
}
}
The rest of the configuration file is the exact copy of the stock one.
What can it be? π€