From 87423ae66a9602a91cc3e69fea64a40465619c4b Mon Sep 17 00:00:00 2001 From: memsuser <108115586+memsuser@users.noreply.github.com> Date: Fri, 24 Jun 2022 05:37:37 -0500 Subject: [PATCH 1/6] Add notes on "filename" form-data field * Added notes about RFC-7578 and "filename" form-data part field treatment by Starlette * Added small comment to file access example --- docs/requests.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/requests.md b/docs/requests.md index 872946638..08743c772 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -112,7 +112,9 @@ state with `disconnected = await request.is_disconnected()`. #### Request Files -Request files are normally sent as multipart form data (`multipart/form-data`). +Request files are normally sent as multipart form data (`multipart/form-data`). + +**`!`** As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form-data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile` object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw string. When you call `await request.form()` you receive a `starlette.datastructures.FormData` which is an immutable multidict, containing both file uploads and text input. File upload items are represented as instances of `starlette.datastructures.UploadFile`. @@ -138,7 +140,7 @@ For example, you can get the file name and the contents with: ```python form = await request.form() -filename = form["upload_file"].filename +filename = form["upload_file"].filename # or form.get("upload_file") contents = await form["upload_file"].read() ``` From 158601bb1bc98df6a2ea79dbeff035b7096a352e Mon Sep 17 00:00:00 2001 From: memsuser <108115586+memsuser@users.noreply.github.com> Date: Fri, 24 Jun 2022 05:49:16 -0500 Subject: [PATCH 2/6] Update docs/requests.md Wrapped notes Co-authored-by: Marcelo Trylesinski --- docs/requests.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/requests.md b/docs/requests.md index 08743c772..4047ff659 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -114,7 +114,13 @@ state with `disconnected = await request.is_disconnected()`. Request files are normally sent as multipart form data (`multipart/form-data`). -**`!`** As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form-data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile` object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw string. +!!! note + As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file + assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form- + data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps + Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile` + object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw + string. When you call `await request.form()` you receive a `starlette.datastructures.FormData` which is an immutable multidict, containing both file uploads and text input. File upload items are represented as instances of `starlette.datastructures.UploadFile`. From 9b00289c4ac6b68cb3779f73d43c9d716d0309ce Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Sat, 25 Jun 2022 11:36:55 -0700 Subject: [PATCH 3/6] Update docs/requests.md Co-authored-by: Marcelo Trylesinski --- docs/requests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requests.md b/docs/requests.md index 4047ff659..cce2c6cdc 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -116,7 +116,7 @@ Request files are normally sent as multipart form data (`multipart/form-data`). !!! note As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file - assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form- + assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form- data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile` object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw From dd306b2b5b246604d3a85c352b91d08e75915f62 Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Sun, 26 Jun 2022 21:32:22 -0700 Subject: [PATCH 4/6] Update docs/requests.md Co-authored-by: Marcelo Trylesinski --- docs/requests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requests.md b/docs/requests.md index cce2c6cdc..13ab4965e 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -146,7 +146,7 @@ For example, you can get the file name and the contents with: ```python form = await request.form() -filename = form["upload_file"].filename # or form.get("upload_file") +filename = form["upload_file"].filename contents = await form["upload_file"].read() ``` From 5aa1c26ac35df796fcc8e3a5823ccfc77efd4371 Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Sun, 26 Jun 2022 21:34:12 -0700 Subject: [PATCH 5/6] move note to end of section --- docs/requests.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/requests.md b/docs/requests.md index 13ab4965e..ab5c11f3f 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -114,14 +114,6 @@ state with `disconnected = await request.is_disconnected()`. Request files are normally sent as multipart form data (`multipart/form-data`). -!!! note - As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file - assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form- - data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps - Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile` - object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw - string. - When you call `await request.form()` you receive a `starlette.datastructures.FormData` which is an immutable multidict, containing both file uploads and text input. File upload items are represented as instances of `starlette.datastructures.UploadFile`. @@ -150,6 +142,13 @@ filename = form["upload_file"].filename contents = await form["upload_file"].read() ``` +!!! note + As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file + assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form- + data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps + Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile` + object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw + string. #### Application From d7da8ad8f84853734b89efdfeb8484fc5dd93306 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 27 Jun 2022 06:52:55 +0200 Subject: [PATCH 6/6] Apply suggestions from code review --- docs/requests.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/requests.md b/docs/requests.md index ab5c11f3f..a50c0753f 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -112,7 +112,7 @@ state with `disconnected = await request.is_disconnected()`. #### Request Files -Request files are normally sent as multipart form data (`multipart/form-data`). +Request files are normally sent as multipart form data (`multipart/form-data`). When you call `await request.form()` you receive a `starlette.datastructures.FormData` which is an immutable multidict, containing both file uploads and text input. File upload items are represented as instances of `starlette.datastructures.UploadFile`. @@ -142,7 +142,7 @@ filename = form["upload_file"].filename contents = await form["upload_file"].read() ``` -!!! note +!!! info As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form- data; name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps