Symfony return 405 error on POST multipart request

I Try to send a multipart/form-data request to my API build with Symfony but I’ve an incredible problem :

My controller (API) is configured to only accept POST request (OK).
But when I send a POST request to this endpoint with a file, result vary :

  • with small/medium file, all working great.
  • with "big" file (~250Mo) Symfony return No route found for "GET /api/v1/file": Method Not Allowed (Allow: POST)

I cry since many hours but I can’t find why !

My Api endpoint controller :

/**
   * @Route("/file", name="file_post", methods={"POST"})
   * Permet de publier un fichier
   */
  public function create( Request $request, SerializerInterface $serializer, ValidatorInterface $validator, string $uploadDir, LogService $log ): Response {
    //File vérifications
    $uploadedFile = $request->files->get( 'file' );
    if ( !$uploadedFile ) {
[...]

My Client function (who emit my request) :

 public static function uploadFile( $data, $file_path, $uuid ) {
    $formFields = [
      'media' => $uuid,
      'size'  => (string) $data['filesize'],
      'metas' => array_map( function ( $el ) {return (string) $el;}, $data ),
      'file'  => DataPart::fromPath( $file_path ),
    ];
    $formData = new FormDataPart( $formFields ); // Nécessaire pour le 'multipart/form-data' quand on envoie des fichiers

    try {
      $response = self::getHttpClient()->request( 'POST', 'file', [
        'headers' => self::getHeaders( $formData->getPreparedHeaders()->toArray() ),
        'body'    => $formData->bodyToString(),
      ] );
      if ( $response->getStatusCode() !== 200 ) {
        return new WP_Error( $response->getStatusCode(), $response->getContent() );
      }
    } catch ( Throwable $exception ) {
      return new WP_Error( $exception->getCode(), $exception->getMessage() );
    }
    return $response->toArray();
  }

Why Symfony say me I send GET when I send POST request !?

ps:
I’ve checked, re-checked and re-re-checked all PHP params (post_max_size, max_execution_time, max_input_time, upload_max_filesize). all is up to my big file size…

What is the problem ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *