expressjs / expressjs/multer

Add an example to the docs about how to send a file from JavaScript

Open
#673 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.1k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
21

Description

Hey there, I was just checking the main readme file a few weeks ago. I remember that I was looking for an example about how to send a file from within my JavaScript code from a React app. So I just found the solution on another site, but wouldn't it be nice to add a JavaScript example, just to make the life a bit easier to newcomers 😄.

An example like this one:
JavaScript
```javascript
function uploadFile(event) {

if ( event.target.files && event.target.files[0] ) {

let reader = new FileReader();
reader.readAsDataURL( event.target.files[0] );
const fileToSend = event.target.files[0];

const url = '/profile';
const formData = new FormData();
formData.append( 'avatar', fileToSend);

}

}
```

HTML
```html

```

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.