Skip to content

docs: add FormData upload examples - #896

Open
davidmashe wants to merge 2 commits into
expressjs:mainfrom
davidmashe:davidmashe/add_formdata_example
Open

docs: add FormData upload examples#896
davidmashe wants to merge 2 commits into
expressjs:mainfrom
davidmashe:davidmashe/add_formdata_example

Conversation

@davidmashe

@davidmashe davidmashe commented May 20, 2020

Copy link
Copy Markdown

Adds an examples/ folder with two small end-to-end samples — a browser FormData upload of a blob and of an image — each with an express server using multer and a static page that posts with fetch. 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

@davidmashe
davidmashe requested review from ghinks and jonchurch June 10, 2020 14:38

const theText = document.getElementById('the-text').value;
const formData = new FormData();
const blob = new Blob([theText], { type: 'text/plain' });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@davidmashe davidmashe Jun 11, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if have a second example with an image upload feature ?

Comment thread examples/FormData/package.json Outdated
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, can do

Comment thread examples/FormData/public/index.html Outdated

fetch('http://localhost:3000/stats', options)
.then(res => res.text())
.then(() => console.log('upload received'));

@jonchurch jonchurch Jun 10, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good ideas, will do

@jonchurch jonchurch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@davidmashe
davidmashe requested a review from jonchurch June 25, 2020 01:21
@davidmashe

Copy link
Copy Markdown
Author

Pushed update, added FormDataImage example and added improvements based on comments

@ghinks ghinks left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, David.

@UlisesGascon UlisesGascon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @davidmashe!

LGTM 🚀

@davidmashe

Copy link
Copy Markdown
Author

Is this ok to merge?

@UlisesGascon
UlisesGascon deleted the branch expressjs:main May 22, 2025 13:47
@UlisesGascon UlisesGascon reopened this May 22, 2025
@UlisesGascon
UlisesGascon changed the base branch from master to v2 May 22, 2025 13:54
@socket-security

socket-security Bot commented May 22, 2025

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​multer@​2.3.010010010087100
Addednpm/​express@​5.2.19710010087100

View full report

@socket-security

socket-security Bot commented May 22, 2025

Copy link
Copy Markdown

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.

View full report

@UlisesGascon
UlisesGascon force-pushed the main branch 2 times, most recently from 2ad8b68 to eef7444 Compare August 28, 2026 18:44
davidmashe and others added 2 commits August 29, 2026 16:47
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.
@UlisesGascon
UlisesGascon force-pushed the davidmashe/add_formdata_example branch from 28e9be7 to 8fafa8c Compare August 29, 2026 14:48
@UlisesGascon UlisesGascon changed the title Davidmashe/add formdata example docs: add FormData upload examples Aug 29, 2026

@UlisesGascon UlisesGascon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that now is in a much better shape. @jonchurch can you have a lock and remove the blocker? 🙏

@UlisesGascon UlisesGascon self-assigned this Aug 29, 2026
@UlisesGascon UlisesGascon added this to the 2.4.0 milestone Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[docs, help wanted] Frontend Usage Examples

5 participants