-
-
Notifications
You must be signed in to change notification settings - Fork 230
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
Ajax Files Upload #748
Ajax Files Upload #748
Conversation
…ored upon Save This improves the Save task tremendously as now there is no longer the need of waiting for the files to finish uploading. Fully backward compatible, `file` field now includes also a `limit` and `filesize` option in the blueprints. The former determines how many files are allowed to be uploaded when in combination with `multiple: true` (default: 10), the latter determines the file size limit (in MB) allowed for each file (default: 5MB)
…et stored in an unexpected way
…es that haven’t been saved yet, from the flash object session
# Conflicts: # themes/grav/css-compiled/template.css # themes/grav/css-compiled/template.css.map
|
…the flash object session
…ne area to pick a file
# Conflicts: # CHANGELOG.md # themes/grav/css-compiled/preset.css # themes/grav/css-compiled/preset.css.map # themes/grav/css-compiled/template.css # themes/grav/css-compiled/template.css.map # themes/grav/js/admin.min.js # themes/grav/js/vendor.min.js
# Conflicts: # CHANGELOG.md # themes/grav/js/admin.min.js # themes/grav/templates/partials/base.html.twig
# Conflicts: # themes/grav/js/admin.min.js
…param and dot notations at the same time
…tion on new lists items)
Tested, all looks good to me! |
Im having some problems using this in the front end. BluePrint: header.logo:
type: File
destination: '@self'
multiple: false
accept:
- image/*
label: Select Project logo (256px X 390px) Output to MD: logo:
user/pages/01.demo-client/01.project-001/project-logo.png:
name: project-logo.png
type: image/png
size: 7724
path: user/pages/01.demo-client/01.project-001/project-logo.png Things I have tried in TWig {{page.header.logo}} {# Returns Array String error #}
{{page.header.logo.path}} {# Nothing returned #}
{{page.header.logo.0.path}} {# Nothing returned #}
{{ page.media[page.header.logo].url }} {# Returns Array String error #}
{{ page.media[page.header.logo.path].url }} {# Nothing returned #}
{{ page.media[page.header.logo.0.path].url }} {# Nothing returned #} Can you explain how I can actually use an image uploaded with this method in my front end please? |
Hi @metadiv, this would have been probably best opened as a new issue for question. You can access your values via: {% for filePath, fileData in page.header.logo %}
<img src="{{ filePath }}" alt="{{ fileData.name }}" />
{% endfor %} |
Thank you for the reply @w00fz , Can I suggest that someone adds this to the grav docs (I couldn't find it but if its there my apologies) I also discovered you can use the page.media[] and the |
This is a work in progress, mostly working, rework of the
file
field.What Changes and How It Works
The
file
field is now decoupled from the Save task and doesn't rely anymore on the nativefile
type. Instead, files drag and dropped into a field are now automatically uploaded, validated and held in a queue until the Save task kicks in. Same goes for removal of files, they are now Ajaxified, allowing the page to not be reloaded.This implementation speeds up tremendously how the Save work, because now there is no longer the need of waiting for all the file to finish uploading, before the Save tasks can continue.
Because the uploaded files are held in a session queue until Save, if the user refreshes or leaves the current page, all uploaded files will be discarded.
Files settings and stored values are fully backward compatible, in addition there are a couple new options and enhancements.
New Options
limit
A great addition that wouldn't be possible with the native
file
type implementation islimit
. It allows to constrain the number of allowed files for an individual field. Ifmultiple: true
is not enabled (which it isn't by default),limit
automatically falls back to1
.filesize
Another addition that the native
file
type implementation doesn't permit isfilesize
. This setting allows to constrain the maximum size (in MB) for a file and for each individual field.Enhanced
accept
In addition to the MIME type,
accept
now alow allows extensions. For example, to only allowyaml
andjson
files:It is also now possible to allow any file by simply using the
*
(star) notation:accept: [‘*’]
.destination
Destination has been enhanced to allow
self@
as well aspage@:
andtheme@:
prefixes.Example of usage, assuming we have a blog item at the route
/blog/ajax-upload
(physical location beinguser/pages/02.blog/ajax-upload
), with thepage@:
prefix the destination would be:What's Missing
onPagesInitialized
to clear out orphan files from thetmp://
location.This will be added in the file field docs as they need updating anywayrandom_name
andavoid_overwriting
settings are not documented.On Save and in single file mode, there is currently no logic to delete the previously stored file, leaving it as orphan.No longer needed since a file needs to be removed before you can upload a new one