Silent sqlpage.persist_uploaded_file()
option?
#278
-
Hi @lovasoa, Wow, great new feature: persist_uploaded_file()! It seems an ideal use case is gallery stuffing (where you're just stuffing some files somewhere, storing the file paths in the database) but not quite right for updating image fields. For instance, if we have an update-profile form: update-profile-form.sql select 'form' as component,
'update-profile.sql' as action;
select
'id' as name,
'hidden' as type;
select
'first_name' as name;
select
'image' as name,
'file' as type,
'image/png, image/jpeg' as accept; update-profile.sql set image_path = sqlpage.persist_uploaded_file('image');
update profiles set first_name = :first_name where id = :id;
update profiles set image = image where $image_path is not null and id = :id; This works nicely the first time, but if we don't supply an image (say we only want to update the name), we get a SQLPage error along the lines of "No uploaded image". Perhaps there is there a way to avoid running the I know we want to avoid turning SQLPage into a programming language 😄 so maybe the function can instead return silent if no file is provided, as with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
You can redirect the user before the call to persist_uploaded_file using the redirect component if there was no uploaded file. |
Beta Was this translation helpful? Give feedback.
-
@matthewlarkin , the problem is finally fixed :) Change available on main, will be in 0.23 |
Beta Was this translation helpful? Give feedback.
Oh, I see, you are talking about the case when the user did submit the form that contained a file upload field, but left it blank. Not the case of the user loading the URL of the form target directly, or submitting another form that did not contain a file input.
By default, the browser will send an empty file, with a mime type of
application/octet-stream
.You can use that to trigger the redirection:
I'll add this to the official "image gallery" example.