I am new to symfony4 and I am following youtube tutorial, to make todo list app with FOSRestBundle.
The problem I encounter is that I can't upload image to the server using PATCH method.
here is controller my function:
use FOS\RestBundle\Request\ParamFetcher;
/**
* @Rest\FileParam(name="image", description="The background of the list", nullable=false, image=true)
* @param ParamFetcher $paramFetcher
* @param int $id
* @return int
*/
public function backgroundListsAction(ParamFetcher $paramFetcher, int $id)
{
var_dump($paramFetcher->get('image'));
return count($_FILES);
}
here is bin/console debug:router
log:
------------------ -------- -------- ------ ----------------------------
Name Method Scheme Host Path
------------------ -------- -------- ------ ----------------------------
background_lists PATCH ANY ANY /api/lists/{id}/background
get_lists GET ANY ANY /api/lists
get_list GET ANY ANY /api/lists/{id}
post_lists POST ANY ANY /api/lists
get_lists_tasks GET ANY ANY /api/lists/{id}/tasks
put_lists PUT ANY ANY /api/lists
------------------ -------- -------- ------ ----------------------------
and I tried several options:
1) As author of tutorial done it with curl, didn't work for me:
curl -X POST -F image=@/home/jake/Pobrane/matrixbg.jpeg -F method=PATCH http://localhost:8000/api/lists/1/background
I received an error:
{"code":405,"message":"No route found for \"POST \/api\/lists\/1\/background\": Method Not Allowed (Allow: PATCH)"}
2) I tried also curl this way:
curl -X PATCH -F image=@/home/jake/Pobrane/matrixbg.jpeg http://localhost:8000/api/lists/1/background
Than error I got was:
{"code":400,"message":"Parameter \"image\" of value \"NULL\" violated a constraint \"This value should not be null.\""}
3) So last thing I tried was using postman, which ended up with same result as in second case