-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Added #9594 : Feature api image uploads and remove #9767
Conversation
Hi there - thanks for this! This looks great, but can you make these changes against the Thanks! |
Ups. I actualy have done this against develop , but missed it when doing pull request. |
@snipe What you think, should this be rewritten with new ApiImageUploadRequest class that would allow json image uploads? More I think about this, more I like json based alternative to multipart/form-data. |
@PetriAsi - thanks! Re: whether this should be written with a ApiImageUploadRequest, my biggest challenge there is just the old DRY pain in the arse. We try really hard to not repeat validation, etc, since when it changes in one place, we invariably forget to change it in another. What's the intent here, that images get uploaded and resized via the API? If so, I'd be more inclined to modify the ImageUploadRequest to look for an |
(..Is there something wrong with Codact as it throws errors on security scan) @snipe Yes, my intention is that api should do same verifications and manipulations to images uploaded via api that it does to images uploaded from web gui. As I see api image upload can be divided two separate problems that can be resolved independently.
As problem 1 can be treated as resolved with this PR. And For json formatted image uploads, I could make new separate issue/PR. As you said for DRY it's better modify ImageUploadRequest to work with json formatted requests instead of duplicating current code to new class. I'll think ways to implement validation rules and file handling logic that will work with multipart/form-data and json formatted inputs. |
@snipe , @uberbrady This is now ready to pull, image uploads are working with json and multipart/form-data. File type restrictions are working as expected and all image manipulation is shared no matter where image came from. I added json base64 decoding as trait, goal was decode files before validation and add them to $request->files, but I could not find way to add file to request. And I really tried. :) But modifying request fields was working ,so trait converts base64 encoded field to UploadedFile, and that did it! |
And now a special image_source field isalso handled with ConvertsBase64ToFiles. |
@uberbrady ,is there something that I can do or should do with this PR ? And I could make v6 version of PR also if I just know what branch I should use. :) |
@PetriAsi I've looked over the PR a few days ago and I thought it seemed very pretty and well-built to me - I think we just need to figure out if we want to take it against current develop, or against our v6 integration branch. We should hopefully have an answer for you today. |
@uberbrady Thanks for info. I'm not trying to rush, maybe I'm just over excited for my first feature PR. I hope that you can take it against current develop. I also tested it again v6-integration and it seems to fit there as well, just with little manual tweaking. |
Love your excitement! :) I’m willing to take this into develop - Can you make it work against the develop-v6-integration branch too? (This is all going to be awful merge conflict hell right before v6 releases, but…) |
@snipe Yes, I love my excitement. That's what moves me , many times I'm just a passenger. :) |
Fixed #9767 : Feature/api image uploads legacy image_source property support
Hi @PetriAsi - I've merged this into master and tagged it into v5.2.0, but I'm not sure how we should handle the API documentation on this.
|
@snipe This simple format works fine for single image fields, but if we like to support uploading multiple files once (ie. for assets) we need format that carry also filenames. But that will be another story. It's also possible to submit image upload request as multipart/form-data to api, without json formatting. Actually all api requests can be done as form requests. |
Description
Fixes #9594, #9483,#9413,#5007
Allow images to be added and removed via api for accessories, assets, asset models, categories,companies, components, consumables,departments, locations, manufacturers, suppliers and users. That great news for for automation and data sync.
So with this PR you can use 'image' or 'image_delete' attributes to api and result are expected.
I added image support by allowing multipart/form-data requests to api . As there's already ImageUploadRequest class that I used for updating images and also image deletes. So no need to maintain duplicate any code for api images handling.
POST request are working without anything special, but PUT and PATCH will require additional '_method' attribute containing request method. That's due to how php/laravel handles multipart requests.
Pros: You can use 'image' or 'image_delete' attributes to api and result are expected. Just send request as multipart/form-data and you are done. Sending images with multipart request needs little server resources. Sending image is straightforward cause no need to convert it to base64 before sending.
Cons: Setting images via json formatted request is not possible with this PR.
@snipe if you like keep api just for json request, then this can be done in new request class like ApiImageUploadRequest that would handle encoded image-fields and image_deletes.
There's also undocumented api for assets that accepts image_source attribute as base64 encoded images #6146 . As "image" field cannot be currently set via API, would it be acceptable to use direcly "image" field instead of "image_source"? This image_source feature can and meby should be combined to ApiImageUploadRequest.
Type of change
How Has This Been Tested?
Image uploads tested with curl command like:
Test Configuration:
Checklist: