07 - Symfony 4 REST: File upload

preview_player
Показать описание

I feel like an asshole that i didn't include any validation to make sure that the actual file is an image, SIKE, just kidding i did.

Рекомендации по теме
Комментарии
Автор

thank you man for your videos, i love it and im learning from it

medkacem
Автор

how to use chunked upload with rest api and angular?

jaspreetmaan
Автор

Hey, thank you for this video series! It's great but I get a few errors in my controller and Terminal, maybe you can help?

1st This line

return $this->view($data, Response::HTTP_CREATED);
Is giving the following error:
Return value is expected to be '\App\Entity\TaskList[]', '\FOS\RestBundle\View\View' returned

2nd Also this line is throwing an error in the terminal
@Rest\RequestParam(name="title", description="Title of the list", nullable=false)
Do I have to import/install anything or provide a use statement to make it work? (I get the following error:


Any help would be highly appreciated :)

AnaisUrlichs
Автор

Thanks a lot! BTW, how to test such a case?

I'm trying this:

$scan = new UploadedFile('/path/to/my/file', 'filename.jpg', 'image/jpeg');
/** @var KernelBrowser $client */
$client = static::createClient();
$client->request('POST', "my/route", [], ['scan' => $scan]);

But getting empty $_FILES array, while your CURL method works fine.

p.s. UploadedFile object is OK

kekcius
Автор

I have a problem with the curl command on windows.

This gives me no errors but just nothing happends and the commandline just skips to a new line.

I also tried using postman by inserting the image in de body but that gives me the following error:
code(400) Parameter \"image\" of value NULL

Any ideas? halp plzzz

hanscharbon
Автор

.Hi OverSeas I've a problem with the curl commands

mfouakiehibrahim
Автор

you can't send an image in a put request too, you saved me like 2 days of searching lol .. thanks !

light
Автор

I'm using Windows and i've exception when i try to give a path of the file. So, i've paste one file in the same directory with my controller and this is the message : "could not open file" the path : "image=@/.1.Png"

mfouakiehibrahim
Автор

Nice, will you dive into api-platform.

YKvids
Автор

Hi, please how can i do it with symfony 3 ??

khaledthameur
Автор

Hi OverSeas,
when i i change nullable to false " @Rest\FileParam(name="image", description="The background of the list", nullable=false, image=true) "i get this message :


% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 369 0 119 100 250 66 139 0:00:01 0:00:01 --:--:-- 206{"code":400, "message":"Parameter \"image\" of value \"NULL\" violated a constraint \"This value should not be null.\""}


and when its true i get this :
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 284 0 34 100 250 17 130 0:00:01 0:00:01 --:--:-- 147{"message":"Something went wrong"}
Help !

ElyesBoudhina
Автор

you are using ubuntu distro? looks really neat

johnnm.