Log message #4115690

# At Username Text
# Feb 8th 2018, 16:33 neon1024 Then you get, `: Indirect modification of overloaded element of ArrayObject has no effect [`
# Feb 8th 2018, 16:33 neon1024 `The $data parameter is an ArrayObject instance, so you don't have to return it to change the data used to create entities.`
# Feb 8th 2018, 16:33 neon1024 I like the docs stating this, https://book.cakephp.org/3.0/en/orm/saving-data.html#modifying-request-data-before-building-entities
# Feb 8th 2018, 16:32 spencdev Another way, and it could quite possibly be really bad advice, is to use Events. As a last ditch effort to kind of duct tape it together, you could make an event and in your non-plugin model/controller have it fire an event to check if everything saved properly. That may be over engineering something, and like I said, could quite possibly be really bad advice. Take it for what its worth.
# Feb 8th 2018, 16:29 spencdev Yeah, you can. There are a thousand ways to skin this cat. There isn’t a right or wrong way, except ways that just don’t work. But with the plugins, I’m not sure if you can attach behaviors to models in plugins. I could be wrong though, i’ve never done it.
# Feb 8th 2018, 16:27 amit Can we do it in a behavior
# Feb 8th 2018, 16:26 amit One more point is I have models in a plugin too
# Feb 8th 2018, 16:25 amit Exactly
# Feb 8th 2018, 16:25 spencdev Yeap. What you don’t want is database entries without the file existing in the object storage. That just creates confusion for everyone.
# Feb 8th 2018, 16:24 neon1024 Especially with a remote data store
# Feb 8th 2018, 16:23 neon1024 Also consider write failure
# Feb 8th 2018, 16:23 spencdev Depends on how YOU want to do it. I do mine beforeSave, I want to make sure the upload was successful before submitting the db entry because I do validation on the filename before marshaling. That a little outside of what CakePHP does/used for. You could do it the other way, save into the database and afterSave upload the image. If the image doesn’t upload, roll back. I think that’s how that would work.
# Feb 8th 2018, 16:21 neon1024 https://book.cakephp.org/3.0/en/orm/saving-data.html#converting-request-data-into-entities
# Feb 8th 2018, 16:21 neon1024 From the book, https://book.cakephp.org/3.0/en/_images/validation-cycle.png
# Feb 8th 2018, 16:21 amit Yes
# Feb 8th 2018, 16:20 neon1024 As part of patchEntity or newEntity
# Feb 8th 2018, 16:19 amit Any idea how validation is handled before image upload
# Feb 8th 2018, 16:19 amit BUt the problem is with the validations
# Feb 8th 2018, 16:18 amit I have created a plugin to store the image on ObjectStore, and I will include it where I need to upload images
# Feb 8th 2018, 16:18 spencdev Yeah, I remember reading that you can do image resizing with AWS using S3, Lambda, and API gateway. If I remember right it’s a lot of work. Of course that doesn’t do the compression and focal points though
# Feb 8th 2018, 16:13 neon1024 So makes sense for our use-case
# Feb 8th 2018, 16:13 neon1024 It’s for our API, so we don’t need to serve out all the various sizes to our client websites via our api and from our api server
# Feb 8th 2018, 16:11 spencdev It’s kind of pricey, but I can imagine the time this would save on a lot of use cases
# Feb 8th 2018, 16:08 neon1024 My boss sure likes it
# Feb 8th 2018, 16:08 spencdev that is actually really freaking awesome
# Feb 8th 2018, 16:07 spencdev whoa
# Feb 8th 2018, 16:06 spencdev I’ve never heard of it, looking it up now
# Feb 8th 2018, 16:06 neon1024 Thankfully with Imgix we just need a single source image and Imgix will create any requested variants on the fly
# Feb 8th 2018, 16:05 neon1024 Yes, we’ll be using a similar system as I understand it.
# Feb 8th 2018, 16:05 spencdev The downside of that is, if I ever have to manually look for a file in S3 with out access to the database to see the associated filename, I’m kind of out of luck considering there are 17gb of files saved...
# Feb 8th 2018, 16:03 spencdev The user doesn’t interact with anything saving except for the files name, which if I remember right (i’m on my phone), it verifies the name is acceptable before ever even trying to save. For S3, the name is tokenized. The name of the file actually doesn’t have anything to do with where/what it’s being saved as. I think I got the idea from one of the upload plugins.
# Feb 8th 2018, 15:59 neon1024 Wont you end up with images in storage you’re not using though?
# Feb 8th 2018, 15:58 spencdev Don’t get me wrong, I used AWS sdk, but the class interacts with it instead of the models. The models use the class. I do it the other way around though, I make sure the image saves to S3 before saving to the db.
# Feb 8th 2018, 15:57 spencdev I wrote my own class for S3 uploads because a lot of models interact with S3 and straight into the model just looks awful.
# Feb 8th 2018, 15:56 neon1024 I’m yet to start with S3, but it’s on my list of things to do. As we want to implement Imgix as well
# Feb 8th 2018, 15:56 neon1024 But either way :slightly_smiling_face:
# Feb 8th 2018, 15:56 neon1024 Well I bet you could easily wrap that in a Writer class
# Feb 8th 2018, 15:55 amit And I am using there lib to upload file
# Feb 8th 2018, 15:55 amit @neon I am uploading a file on VPS ObjectStore, which is similar like AWS S3
# Feb 8th 2018, 15:54 spencdev S3 saves lives
# Feb 8th 2018, 15:53 neon1024 Unless you’re working on the VPS and saving locally