d718c5a372
CI / windows_test (push) Waiting to run
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / docker_push (duckdb) (push) Waiting to run
CI / docker_push (minimal) (push) Waiting to run
CI / hurl (${{ matrix.example }}) (push) Has been skipped
32 lines
1.4 KiB
SQL
32 lines
1.4 KiB
SQL
-- important: we do not accept file uploads from unauthenticated users
|
|
select 'redirect' as component, '/login.sql' as link -- redirect to the login page if the user is not logged in
|
|
where not exists (
|
|
select true from session
|
|
where
|
|
sqlpage.cookie('session_token') = id and
|
|
created_at > datetime('now', '-1 day') -- require the user to log in again after 1 day
|
|
);
|
|
|
|
-- Redirect the user back to the form if no file was uploaded
|
|
select 'redirect' as component, '/upload_form.sql' as link
|
|
where sqlpage.uploaded_file_mime_type('Image') NOT LIKE 'image/%';
|
|
|
|
insert or ignore into image (title, description, image_url)
|
|
values (
|
|
:Title,
|
|
:Description,
|
|
-- Persist the uploaded file to the local "images" folder at the root of the website and return the path
|
|
sqlpage.persist_uploaded_file('Image', 'images', 'jpg,jpeg,png,gif')
|
|
-- alternatively, if the images are small, you could store them in the database directly with the following line
|
|
-- sqlpage.read_file_as_data_url(sqlpage.uploaded_file_path('Image'))
|
|
)
|
|
returning 'redirect' as component,
|
|
format('/?created_id=%d', id) as link;
|
|
|
|
-- If the insert failed, warn the user
|
|
select 'alert' as component,
|
|
'red' as color,
|
|
'alert-triangle' as icon,
|
|
'Failed to upload image' as title,
|
|
'Please try again with a smaller picture. Maximum allowed file size is 500Kb.' as description
|
|
; |