Chapters
48 Chapters
|
5:13:28
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
33.
Output Properties & Metadata
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial also works great with API Platform 2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.5.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.12.1
"doctrine/doctrine-bundle": "^2.0", // 2.1.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.4.5", // 2.8.2
"nelmio/cors-bundle": "^2.1", // 2.1.0
"nesbot/carbon": "^2.17", // 2.39.1
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", // 5.2.2
"ramsey/uuid-doctrine": "^1.6", // 1.6.0
"symfony/asset": "5.1.*", // v5.1.5
"symfony/console": "5.1.*", // v5.1.5
"symfony/debug-bundle": "5.1.*", // v5.1.5
"symfony/dotenv": "5.1.*", // v5.1.5
"symfony/expression-language": "5.1.*", // v5.1.5
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.5
"symfony/http-client": "5.1.*", // v5.1.5
"symfony/monolog-bundle": "^3.4", // v3.5.0
"symfony/security-bundle": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/validator": "5.1.*", // v5.1.5
"symfony/webpack-encore-bundle": "^1.6", // v1.8.0
"symfony/yaml": "5.1.*" // v5.1.5
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.3.2
"symfony/browser-kit": "5.1.*", // v5.1.5
"symfony/css-selector": "5.1.*", // v5.1.5
"symfony/maker-bundle": "^1.11", // v1.23.0
"symfony/phpunit-bridge": "5.1.*", // v5.1.5
"symfony/stopwatch": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/web-profiler-bundle": "5.1.*", // v5.1.5
"zenstruck/foundry": "^1.1" // v1.8.0
}
}
7 Comments
Hey Ryan, i was wondering if there's a way to only add the fields that needs to be processed differently, in the transformer. For example, i have a File entity with the usual fields: name, extension, mimetype, etc ( those are also db columns ) and beside those i also have a file property that isn't a db column. This file is actually a resource that is sent via api in a multipart format ( or maybe just a link to the resource ) and then i process it.( i save it in s3, then save only the s3 path in my db ). Can i force api platform to use the normal fields on read/write from the entity and use only the file property from the FileInput ( and FileInputDataTransformer), since the only time i need the file field is when i save it to s3 and save its properties to db
Quick mention: i've defined groups for serialization/deserialization in my entity and due to that fact, if i leave them in my entity without adding them in the Dto class, it triggers an error:
Can't get a way to read the property \"extension\" in class \"App\\Data\\File Output\"Hey Petru L.!
Hmm. What if you *don't* create an input DTO at all. Instead, add the non-persisted "file" property to your entity (it sounds like you already have this) and use a custom data persister to handle processing the resource/link on that "file" property (the saving it to s3 part).
Would that work? Or am I missing a complication? With just one "weird" field, this is the first idea that popped into my head. Input/output DTO's are more of a headache, unless you have a lot of differences between your input/output and how your entity looks.
Cheers!
Yeah, it looks like data persister might be the way to go but while this solves my POST problem, i got a similar issue with the GET. For example, after a certain file has been saved into db ( and in s3 ), one user may request that file, and the path field in my db contain only the relative path to the file, i need to transform it into the absolute path and not just that, maybe the user wants a thumbnail of it, and so i'll have to serve the liip-imagine cached thumbnail path, or maybe he request the image of a certain resolution, and i'll have to do some more parsing there too. Should i stick with the DTO for the output or is something better for this case? Thank you
Hey Petru L.!
> i got a similar issue with the GET. For example, after a certain file has been saved into db ( and in s3 ), one user may request that file, and the path field in my db contain only the relative path to the file, i need to transform it into the absolute path
No problem :). Add one (or some) non-persisted fields and use a custom data provider to supply those :). We talk about this a bit earlier in the tutorial - https://symfonycasts.com/sc...
Cheers!
Petru L. , came across another problem... I'm trying to send a multipart request through api and so i enabled the multipart type in api_platform.yaml, then it said it couldn't deserialized and so i turn the deserialization off in the entity and then i got stuck at:
. In the api platform guide to upload file, they create a custom action for it: https://api-platform.com/do.... So maybe that's the only way to do it??
Hey Petru L.!
I've never used API Platform's native file upload tools. But yes, my guess is that the custom action is needed... when you turn deserialization off, then there is no "$data" on the request attributes... and I think the normal, core controller fails. I'm doing a bit of guessing on this, but it would make sense to me :).
Cheers!
"Houston: no signs of life"
Start the conversation!