<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a" -->

---
title: How to Upload Files with JavaScript | daily.dev
description: How to Upload Files with JavaScript is a bit limited to using the native browser form behavior, which causes the page to refresh. In this tutorial, I want to...
canonical: https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Upload Files with JavaScript | daily.dev
og:description: How to Upload Files with JavaScript is a bit limited to using the native browser form behavior, which causes the page to refresh. In this tutorial, I want to...
og:url: https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a
og:image: https://api.daily.dev/og/posts/u5L1SIc7A.png
og:image:alt: How to Upload Files with JavaScript
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Upload Files with JavaScript

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · 5 min read · 54 upvotes · 3 comments

## Summary

How to Upload Files with JavaScript is a bit limited to using the native browser form behavior, which causes the page to refresh. In this tutorial, I want to show you how to do the same thing with JavaScript to avoid the page refresh. That way, you can have the same functionality, but with better user experience.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/upload-files-with-javascript/>

## Community discussion

Top comments from developers on daily.dev.

**@regie28** · 0 upvotes

> This is pretty useful

**@mcoutinho** · 0 upvotes

> To add to this article, you may want to choose to use XHR instead of fetch for upload functionality that doesn't navigate away form the page. The reason is that this also allows you to add a progress indicator.
>
> whatwg has [been looking into](https://github.com/whatwg/fetch/pull/425) a ReadableStream implementation for Fetch for the past 6 years. This would also allow you to add a progress indicator, but since it's taken so long, I wouldn't hold my breath.

**@kwesihackman** · 0 upvotes

> great article Austin! I've always used Axios, thanks for sharing how to do it the vanilla way

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#html](https://daily.dev/tags/html)

[View this post on daily.dev](https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Upload Files with JavaScript","url":"https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a"},"datePublished":"2023-04-06T22:58:45.866Z","dateModified":"2023-04-06T22:58:45.764Z","description":"How to Upload Files with JavaScript is a bit limited to using the native browser form behavior, which causes the page to refresh. In this tutorial, I want to...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1680821923/2e828ab315516dbc2cf9e1a1e2955574","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1680821923/2e828ab315516dbc2cf9e1a1e2955574","isAccessibleForFree":true,"articleSection":"freeCodeCamp","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"freeCodeCamp","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1628412854/logos/freecodecamp","url":"https://daily.dev/sources/freecodecamp"},"commentCount":3,"discussionUrl":"https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":54},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":3}],"keywords":"javascript,html","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"freeCodeCamp","item":"https://daily.dev/sources/freecodecamp"},{"@type":"ListItem","position":3,"name":"How to Upload Files with JavaScript"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-upload-files-with-javascript-u5l1sic7a","comment":[{"@type":"Comment","text":"This is pretty useful","datePublished":"2023-05-09T11:31:28.160Z","url":"https://daily.dev/posts/u5L1SIc7A#c-MoS3TC6l9","author":{"@type":"Person","name":"Reginald Bartiana","url":"https://daily.dev/regie28","image":"https://avatars.githubusercontent.com/u/43838499?v=4"}},{"@type":"Comment","text":"To add to this article, you may want to choose to use XHR instead of fetch for upload functionality that doesn’t navigate away form the page. The reason is that this also allows you to add a progress indicator.\nwhatwg has been looking into a ReadableStream implementation for Fetch for the past 6 years. This would also allow you to add a progress indicator, but since it’s taken so long, I wouldn’t hold my breath.","datePublished":"2023-04-14T10:53:02.994Z","url":"https://daily.dev/posts/u5L1SIc7A#c-8WZZHlbl7","author":{"@type":"Person","name":"Mitchell Coutinho","url":"https://daily.dev/mcoutinho","image":"https://lh3.googleusercontent.com/a/ALm5wu2v2lY4YzABnQ9xIEy67NdwPksQ-AifbV7duyGK=s96-c"}},{"@type":"Comment","text":"great article Austin! I’ve always used Axios, thanks for sharing how to do it the vanilla way","datePublished":"2023-05-02T23:36:29.340Z","url":"https://daily.dev/posts/u5L1SIc7A#c-eEPKfdgb7","author":{"@type":"Person","name":"Eric Hackman","url":"https://daily.dev/kwesihackman","image":"https://avatars.githubusercontent.com/u/2277160?v=4"}}]}
```

