upload image by api laravel controller

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
malik_kat
Posts: 11
Joined: 09 Jan 2024, 09:20

upload image by api laravel controller

Post by malik_kat » 06 May 2024, 08:16

I am working on adding media item to table mshop_media.
I created my controller on this path.

Code: Select all

app\Http\Controllers\AddProductController.php
And added this code

Code: Select all

$context  = app('aimeos.context')->get(); 
$managerMedia    = \Aimeos\MShop::create( $context, 'media' );
$cntlMedia  = \Aimeos\Controller\Common\Media\Factory::create( $context );    
$mediaItem  = $managerMedia->get(175);
$cntlMedia->add($mediaItem,$request->file('img'));
But i get an error when i used this class :

Code: Select all

Aimeos\Controller\Common\Media\Factory
Error Message:

Code: Select all

TypeError: Aimeos\Controller\Common\Media\Standard::add(): Argument #2 ($file) must be of type Psr\Http\Message\UploadedFileInterface, Illuminate\Http\UploadedFile given, called in C:\xampp\htdocs\myshop\app\Http\Controllers\AddProductController.php on line 29 in file C:\xampp\htdocs\myshop\vendor\aimeos\aimeos-core\src\Controller\Common\Media\Standard.php on line 46
PHP Version 8.2.12
Laravel version: 10
Aimeos version: 2023.10
Environment: windows (XAMPP cross-platform web server).

User avatar
aimeos
Administrator
Posts: 7941
Joined: 01 Jan 1970, 00:00

Re: upload image by api laravel controller

Post by aimeos » 06 May 2024, 09:22

Expect a PSR-7 request in your action instead of a Laravel request. Then, you also get a PSR-7 file upload object which you can use:
https://laravel.com/docs/11.x/requests#psr7-requests
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply