- From: Jimmy Wärting <notifications@github.com>
- Date: Fri, 18 Dec 2020 14:34:55 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1130@github.com>
Some demonstration code ```js fd = new FormData() file = new File(['abc'], 'dummy.txt', { type: 'text/plain', lastModified: Date.now() }) fd.set('x', file) await new Response(fd).text() ``` What's generated: ``` ------WebKitFormBoundaryI2aNXnjBifHTBeH1 Content-Disposition: form-data; name="x"; filename="dummy.txt" Content-Type: text/plain abc ------WebKitFormBoundaryI2aNXnjBifHTBeH1-- ``` --- I think some more per-file headers could enhance the server validation for instance. it would be useful to know before you receive the hole file how large a per file size is, not the hole formdata `content-length`. So you can abort upload request prematurely if one is sending a too large file. While we are at it, why can't we as well throw in the less useful `Last-Modified` header as well? that is also known on the client side before it's being uploaded. ``` ------WebKitFormBoundaryI2aNXnjBifHTBeH1 Content-Disposition: form-data; name="x"; filename="dummy.txt" Content-Type: text/plain Content-Length: 3 Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT abc ------WebKitFormBoundaryI2aNXnjBifHTBeH1-- ``` This things could easily be added if you pass in a Blob/File without changing any code. But another idea could also be to allow sending custom headers as well when using the `FormData` api ```js // something like headers = new Headers({ 'Content-Length': 3 }) fd.set('x', file, { headers } ) ``` This could allow for a way to [batch](https://www.arangodb.com/docs/stable/http/batch-request.html) a bunch of requests into one request also. if you get a bit creative I have seen some developer use a custom multipart library to batch multiple request/responses into one As opposite to this a way to read individual per-entries headers could also be useful so you can decode it also. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1130
Received on Friday, 18 December 2020 22:35:07 UTC