HTTP::GETDATA
1g 2023-11-14 laplante@plcb.ca GOWEB/HTTPauthor: laplante@plcb.ca date: 2023-11-14 title: “HTTP::GETDATA Function” version: 1.0.1 section: 1g
http::getdata — Read request parameters and handle file uploads
http::getdata([postonly: bool, uuid: bool, error: err, max_upload_size: int, max_upload_size_file: int, progress: string, action: string])
The http::getdata
function retrieves data sent either through query
parameters or multipart form submissions.
It also supports file uploads with advanced control such as file size
limits, per-file configuration, and upload progress tracking.
When the progress
parameter is set, the function records the upload
status in a database table.
The table must contain the following fields:
getdata
.Uploaded data is not deleted after completion.
DROP TABLE IF EXISTS `progress_table`;
CREATE TABLE `progress_table` (
`uuid` varchar(255) DEFAULT NULL,
`size` int(11) DEFAULT NULL,
`read_file` int(11) DEFAULT NULL,
`pourc` double DEFAULT NULL,
`file` varchar(1024) DEFAULT NULL,
`param` varchar(255) DEFAULT NULL,
`index_file` int(11) DEFAULT NULL,
`nb_file` int(11) DEFAULT NULL,
`nb_file_done` int(11) DEFAULT NULL,
`total_size` int(11) DEFAULT NULL,
`total_read` int(11) DEFAULT NULL,
`total_pourc` double DEFAULT NULL,
UNIQUE KEY `uuid` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
{
"photo1": [
{
"content_type": "image/png",
"filename": "moi.png",
"filetype": "image/png",
"new_filename": "1-1-1-1-1-1-1-moi.png",
"param": "photo1",
"size": 560879,
"upload_dir": "/Users/laplante/go/src/goweb/www/upload"
},
{
"content_type": "image/png",
"filename": "Capture d’écran, le 2023-09-06 à 12.49.16.png",
"filetype": "image/png",
"new_filename": "1-Capture d’écran, le 2023-09-06 à 12.49.16.png",
"param": "photo1",
"size": 104981,
"upload_dir": "/Users/laplante/go/src/goweb/www/upload"
}
],
"photo2": {
"content_type": "image/png",
"filename": "Capture d’écran, le 2023-09-13 à 06.54.27.png",
"filetype": "image/png",
"new_filename": "Capture d’écran, le 2023-09-13 à 06.54.27.png",
"param": "photo2",
"size": 310819,
"upload_dir": "/Users/laplante/go/src/goweb/www/upload"
},
"upload_from": "",
"uuid": "fc7edc9f-315b-4370-9395-d1baa37fc537"
}
goweb.toml
setting.max_upload_size
.// Simple usage with default size
upload := getdata(error: err, max_upload_size: 1)
// Set maximum form size and per-file limits
upload := getdata(error: err, max_upload_size: 10000000, files: { "photo1": { "max_upload_size": 1 } })
// Restrict by allowed file types
upload := getdata(error: err, filetype: [ "a", "b" ])
upload := getdata(error: err, max_upload_size: 10000000, filetype: [ "image/png" ])
// Per-file type restrictions with action policy
upload := getdata(error: err, max_upload_size: 10000000, filetype: [ "image/png" ],
files: { "photo1": { "max_upload_size": 10000000, "filetype": [ "image/jpeg" ] } })
upload := getdata(error: err, max_upload_size: 10000000, filetype: [ "image/png" ], action: "error")
upload := getdata(error: err, max_upload_size: 10000000, filetype: [ "image/png" ], action: "overwrite")
upload := getdata(error: err, max_upload_size: 10000000, filetype: [ "image/png" ], action: "rename")
// Per-file action override
upload := getdata(error: err, max_upload_size: 10000000, filetype: [ "image/png" ], action: "rename",
files: { "photo2": { "action": "error" } })