docs: add FormData upload examples - #896
Conversation
|
|
||
| const theText = document.getElementById('the-text').value; | ||
| const formData = new FormData(); | ||
| const blob = new Blob([theText], { type: 'text/plain' }); |
There was a problem hiding this comment.
I think this might be confusing to some folks who are just looking to upload an image or something. That said, this is a great example of uploading a blob!
There was a problem hiding this comment.
what if have a second example with an image upload feature ?
| "description": "", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" |
There was a problem hiding this comment.
| "test": "echo \"Error: no test specified\" && exit 1" | |
| "test": "echo \"Error: no test specified\" && exit 1", | |
| "start": "node index.js" |
Maybe add a start script?
|
|
||
| fetch('http://localhost:3000/stats', options) | ||
| .then(res => res.text()) | ||
| .then(() => console.log('upload received')); |
There was a problem hiding this comment.
| .then(() => console.log('upload received')); | |
| .then(res => { | |
| if (res.ok) { | |
| alert('upload received') | |
| } else { | |
| alert('something went wrong, the request failed') | |
| console.error(res.statusText) | |
| }}) |
This could probably be an alert, and we can add some error handling here.
jonchurch
left a comment
There was a problem hiding this comment.
Hey sorry this took so long to review! Thank you very much for working on this.
I think it needs a short readme, but this is a great start.
|
Pushed update, added FormDataImage example and added improvements based on comments |
UlisesGascon
left a comment
There was a problem hiding this comment.
Thanks a lot @davidmashe!
LGTM 🚀
|
Is this ok to merge? |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
2ad8b68 to
eef7444
Compare
Use express 5 and multer 2, drop the lockfiles and the committed upload, ignore the uploads folder, remove a debug route, link the examples from the README.
28e9be7 to
8fafa8c
Compare
UlisesGascon
left a comment
There was a problem hiding this comment.
I think that now is in a much better shape. @jonchurch can you have a lock and remove the blocker? 🙏
Adds an
examples/folder with two small end-to-end samples — a browserFormDataupload of a blob and of an image — each with an express server using multer and a static page that posts withfetch. Linked from the README.Rebased onto
main: the original commits are squashed into one, plus a cleanup commit (express 5 / multer 2, no lockfiles, no committed upload, uploads folder ignored, debug route removed).Closes #883