✨ (pagetop): Añade subida y descarga de archivos
- `web::Upload` guarda los archivos de un envío multipart en disco por trozos, con nombre aleatorio, extensiones y tamaño máximo por archivo. `receive()` deserializa además los campos de texto con serde_qs. - `web::Download` sirve un archivo subido con rangos y peticiones condicionales, inline sólo para tipos pasivos y con nosniff. - `form::File`, componente para elegir archivos, y soporte en Bootsier. - Límite del cuerpo según el tipo de contenido: `server.max_body_size` baja a 2 MiB y el nuevo `upload.max_request_size` (32 MiB) se aplica sólo a multipart/form-data.
This commit is contained in:
parent
5540c0c6a0
commit
f3228d6b59
21 changed files with 2240 additions and 17 deletions
|
|
@ -166,6 +166,8 @@ async fn form_controls(request: HttpRequest) -> Result<Markup, ErrorPage> {
|
|||
.with_id("form-text")
|
||||
.with_action("/")
|
||||
.with_method(form::Method::Post)
|
||||
// Necesaria para enviar los archivos de form::File.
|
||||
.with_enctype(form::Enctype::Multipart)
|
||||
// Campos de texto (form::input::Field).
|
||||
.with_child(
|
||||
form::Fieldset::new()
|
||||
|
|
@ -251,6 +253,26 @@ async fn form_controls(request: HttpRequest) -> Result<Markup, ErrorPage> {
|
|||
.with_help_text(Lc::t("help_rating", &LOC)),
|
||||
),
|
||||
)
|
||||
// Selección de archivos (form::File).
|
||||
.with_child(
|
||||
form::Fieldset::new()
|
||||
.with_legend(Lc::t("fieldset_file", &LOC))
|
||||
.with_child(
|
||||
form::File::new()
|
||||
.with_name("photo")
|
||||
.with_label(Lc::t("label_photo", &LOC))
|
||||
.with_accept("image/jpeg,image/png")
|
||||
.with_help_text(Lc::t("help_photo", &LOC)),
|
||||
)
|
||||
.with_child(
|
||||
form::File::new()
|
||||
.with_name("attachments")
|
||||
.with_label(Lc::t("label_attachments", &LOC))
|
||||
.with_accept(".pdf")
|
||||
.with_multiple(true)
|
||||
.with_help_text(Lc::t("help_attachments", &LOC)),
|
||||
),
|
||||
)
|
||||
// Campo oculto (form::Hidden).
|
||||
.with_child(form::Hidden::field("origin", "form-text"))
|
||||
// Botonera de acciones.
|
||||
|
|
|
|||
|
|
@ -73,6 +73,12 @@ fieldset_range = Slider
|
|||
label_rating = Overall rating
|
||||
help_rating = From 1 (very poor) to 10 (excellent).
|
||||
|
||||
fieldset_file = Files
|
||||
label_photo = Profile picture
|
||||
help_photo = JPEG or PNG image. This example does not save it.
|
||||
label_attachments = Attachments
|
||||
help_attachments = You can choose several PDF files.
|
||||
|
||||
btn_submit = Submit
|
||||
btn_reset = Reset
|
||||
btn_cancel = Cancel
|
||||
|
|
|
|||
|
|
@ -73,6 +73,12 @@ fieldset_range = Control deslizante
|
|||
label_rating = Valoración general
|
||||
help_rating = De 1 (muy malo) a 10 (excelente).
|
||||
|
||||
fieldset_file = Archivos
|
||||
label_photo = Foto de perfil
|
||||
help_photo = Imagen JPEG o PNG. En este ejemplo no se guarda.
|
||||
label_attachments = Documentos adjuntos
|
||||
help_attachments = Puedes elegir varios archivos PDF.
|
||||
|
||||
btn_submit = Enviar
|
||||
btn_reset = Restablecer
|
||||
btn_cancel = Cancelar
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue