Skip to content
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

MultipartDecoder requires PECL extension to update file on existing resource #1975

Open
BurningDog opened this issue Sep 10, 2024 · 2 comments

Comments

@BurningDog
Copy link

BurningDog commented Sep 10, 2024

The context of using MultipartDecoder is when we are Uploading to an Existing Resource with its Fields. MultipartDecoder works as expected when an API POST is done and a new resource is created.

However, at some point we might want to replace the existing uploaded file with a new file. This is most likely done with a PATCH i.e. define this operation (same as with the POST):

        new Patch(
            outputFormats: ['jsonld' => ['application/ld+json']],
            inputFormats: ['multipart' => ['multipart/form-data']],
        ),

However, there's no way I can see in the $request to get the values out of the transmitted data, i.e. both $request->request->all() and $request->files->all() are null.

The curl looks like so:

curl -X 'PATCH' \
  'https://localhost/api/books/1' \
  -H 'accept: application/ld+json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'isbn=' \
  -F 'title=' \
  -F 'description=' \
  -F 'author=' \
  -F '[email protected];type=image/jpeg'

I assume that it's not possible to PATCH multipart/form-data, but then this means that we can never update an image via the API.

What do we do instead in this case?

@NikDevPHP
Copy link

NikDevPHP commented Sep 10, 2024

@BurningDog Hello, in PHP it basically doesn't work.

https://bugs.php.net/bug.php?id=55815
symfony/symfony#9226

But you can use
https://pecl.php.net/package/apfd

You can also use the POST method to upload files to the server.

@BurningDog BurningDog changed the title MultipartDecoder only works on POST not PATCH MultipartDecoder requires PECL extension to update file on existing resource Sep 10, 2024
@BurningDog
Copy link
Author

Good news - this will be fixed in php 8.4! https://wiki.php.net/rfc/rfc1867-non-post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants