Hello,
First of all, thank you so much for Flex Objects. It is an incredibly useful tool and I really enjoy using it!
I am writing to report four issues I encountered when uploading images using Flex Objects.
Since I am not a professional programmer, I am not entirely sure if the following issues stem from the same root cause or if they are a combination of multiple separate problems. Please let me know if I should isolate these into different topics, and I will gladly split them up.
I have noticed the following four issues:
- Uploading fails when specifying
destination: 'self@'in the blueprint, even though I configured it based on the official documentation. - When uploading an image via the Admin2 Panel, the file is successfully uploaded to the folder on the first attempt, but it is not written to
item.json. It only gets recorded initem.jsonon the second attempt. - When deleting an image file via the Admin2 Panel, the actual file inside the folder is not deleted.
- When using
destination: 'media://'in the blueprint and uploading an image, the image no longer appears in the Admin2 Panel when I reopen an object I previously created for editing.
Context
I have created a plugin called flex-images, as shown below:
php bin/gpm install admin2
php bin/plugin login new-user # create super user
php bin/gpm install flex-objects
php bin/gpm install devtools
php bin/plugin devtools new-plugin
> Plugin Name -> `flex-images`
> choose an option -> `flex`
> Flex Object Name -> `flex-images`
> choose a storage type -> `folder`
cd ./user/plugins/flex-images/
composer update
cd ../../../
1. Uploading fails when specifying destination: 'self@' in the blueprint.
I have created a blueprint, as shown below:
# user/plugins/flex-images/blueprints/flex-objects/flex_images.yaml
config:
admin:
permissions:
api.flex_images:
type: crudl
list:
title: name
fields:
text:
link: edit
form:
validation: loose
fields:
text:
type: text
label: Text
validate:
required: true
images:
type: file
label: Images
multiple: true
destination: 'self@'
limit: 2
accept:
- image/*
In this state, when attempting to upload a file via the Admin2 Panel, the following error message is displayed:
Failed to upload image1.jpg: Cannot resolve 'self@:' path: scope '' is not a supported owner.
However, if I comment out destination: 'self@' as shown below, it starts working properly:
# user/plugins/flex-images/blueprints/flex-objects/flex_images.yaml
images:
type: file
label: Images
multiple: true
# destination: 'self@' # comment out
limit: 2
accept:
- image/*
According to the official documentation, self@ seems to be the default, but it did not work for me.
(Reference) Cannot upload before creating the object
This might be the intended behavior rather than a bug, but I would also like to report that attempting to upload an image before the Flex Object itself is created results in the following error:
Failed to upload image1.jpg: Method 'POST' is not allowed. Allowed: GET, DELETE, PATCH.
If I first create the object via the Admin2 Panel and then upload the image while updating that existing object, it succeeds.
If possible, it would be highly appreciated if the error message could be something more descriptive.
2. Image is not recorded in item.json on the first upload attempt
After saving an object, if I attempt to upload an image via the Admin2 Panel for the first time, the Save button in the top right remains disabled.
# user/data/flex_images/.../item.json
{"text":"test"}
However, checking the folder confirms that the file has actually been uploaded.
$ ls ./user/data/flex_images/.../
image1.jpg item.json
If I attempt to upload the exact same image again via the Admin2 Panel, the following notification appears, and it successfully gets recorded in item.json.
Object Changed Elsewhere Save To
# user/data/flex_images/.../item.json
{"text":"test","images":{"image1.jpg":{"name":"image1.jpg","type":"image\/jpeg","size":72707,"path":"image1.jpg"}}}
3. Deleted images are removed from item.json but remain in the folder
After uploading image1.jpg and image2.jpg via the Admin2 Panel, if I delete them and then upload image3.jpg, the result is as follows:
{"text":"test","images":{"image3.jpg":{"name":"image3.jpg","type":"image\/jpeg","size":79161,"path":"image3.jpg"}}}
However, looking inside the folder, the actual image files themselves are not deleted.
$ ls ./user/data/flex_images/.../
image1.jpg image2.jpg image3.jpg item.json
4. Saving an image to media:// and reopening the object causes the image to disappear
Write the blueprint as follows:
# user/plugins/flex-images/blueprints/flex-objects/flex_images.yaml
images:
type: file
label: Images
multiple: true
destination: 'media://'
limit: 2
accept:
- image/*
With this method, it is possible to upload the image and create the object at the same time.
However, if I reopen the object created this way in the Admin2 panel, the image disappears.
The image itself exists in `user/media/`, and the image file is alsoentered in `item.json`.