tezvyn:

FormData: The Right Way to Upload Files

Source: developer.mozilla.orgintermediate

FormData is your digital envelope for file uploads. It packages files and text into a `multipart/form-data` payload for `fetch`. Use it in React Native to upload images or videos. The footgun: don't set the `Content-Type` header yourself; `fetch` handles it.

Think of FormData as a digital envelope for complex data. It constructs a set of key/value pairs, including files, into the `multipart/form-data` format that servers expect for uploads. In React Native, you'll use it with `fetch` to send user-picked images, videos, or documents. The main footgun is manually setting the `Content-Type` header. When `fetch` receives a FormData body, it automatically sets the correct header, including the required boundary string. Overriding it will cause the server to reject your request.

Read the original → developer.mozilla.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

FormData: The Right Way to Upload Files · Tezvyn