- From: guest271314 <notifications@github.com>
- Date: Mon, 08 Apr 2019 17:16:54 -0700
- To: w3c/FileAPI <FileAPI@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/FileAPI/issues/126/481053772@github.com>
@andrew-aladev > It is not so complex. People wants to create a file, fix its name, extension, check mime type, manipulate its blob a bit using their own infrastructure with mutable instances or with other immutable objects. That is already possible. > Nobody is using File class in the way it was designed. That is not accurate. Who is "Nobody"? How did you determine that? > Noone wants to extend File To do what? > It is a complete interface failure. Disagree. > People will just change internal wrapper params and creates File only when they need it. That is already possible. Users can create a `FormData` object as a "template" and use `fetch()` or `XMLHttpRequest()` to read/write the contents of one or more files (see Get HTTP Body of Form in JavaScript https://stackoverflow.com/q/40111982) ``` var form = document.querySelector("form"); form.onsubmit = (e) => { e.preventDefault(); var formData = new FormData(); var input = e.target.querySelector("input"); formData.append("file", input.files[0], input.files[0].name); var response = new Response(formData); var stream = response.body; var reader = stream.getReader(); var decoder = new TextDecoder(); reader.read() .then(function processData(result) { if (result.done) { console.log("stream done"); return; } var data = decoder.decode(result.value); console.log(data); return reader.read().then(processData); }) .catch(function(err) { console.log("catch stream cancellation:", err); }); reader.closed.then(function() { console.log("stream closed"); }); } ``` and/or write a form data including one or more "files" (that can be modified at any time) from scratch (see https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html; https://github.com/whatwg/fetch/issues/392; https://github.com/whatwg/html/issues/3040; How to manually create multipart/form-data https://stackoverflow.com/q/47080869). > It looks like FormData is the only class on this planet that uses File in the way it was designed. Not sure what you mean? `FormData` is not the only API shipped with the browser that can create a "file". It is only relatively recently that users could even create a `File` object (or instance). In which specific manner to you want to "extend" `File`? Again, are the use cases? -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/FileAPI/issues/126#issuecomment-481053772
Received on Tuesday, 9 April 2019 00:17:16 UTC