Skip to content

[HttpKernel] Create #[UploadedFile] Attribute to map UploadedFile objects to Controller Arguments #49976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Koc
Copy link
Contributor

@Koc Koc commented Apr 7, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR TBD

#[MapUploadedFile(name: 'photo')] provides UploadedFile as Controller Argument.

Usage example 🔨

class UploadFilesController
{
    public function uploadSingleFile(#[MapUploadedFile] UploadedFile $photo): Response
    {
        // $_FILES['photo'] or 404 response
    }

    public function uploadSingleNullableFile(#[MapUploadedFile] ?UploadedFile $photo): Response
    {
        // $_FILES['photo'] or null
    }

    public function uploadVariadic(#[MapUploadedFile] UploadedFile ...$photos): Response
    {
        // $_FILES['photos'] or 404 response
    }

    /**
     * @param UploadedFile[] $photos
     */
    public function uploadArrayWithCustomName(#[MapUploadedFile('images')] array $photos): Response
    {
        // $_FILES['images'] or empty array
    }
}

🗒️ TODO

  • Cover with tests

return [[]];
}

throw new NotFoundHttpException(sprintf('Missing uploaded file "%s".', $name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a 422 Unprocessable Entity.

@Koc
Copy link
Contributor Author

Koc commented Apr 12, 2023

closing in favor of #49978

@Koc Koc closed this Apr 12, 2023
@Koc Koc deleted the feature/map-uploaded-file branch April 12, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants