{"id":104381,"date":"2020-05-06T13:00:00","date_gmt":"2020-05-06T10:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=104381"},"modified":"2020-05-04T11:21:41","modified_gmt":"2020-05-04T08:21:41","slug":"reactjs-file-upload-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html","title":{"rendered":"ReactJS File Upload Example"},"content":{"rendered":"<p>In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We take a look at how to build a feature to upload files in a ReactJS Application. We will use the ubiquitous XMLHttpRequest Object to post the file data to the server. Also, we will build a simple Server side API to accept the uploaded file. To make things interesting we also provide a progress indicator. <\/p>\n<p>So, without further ado let us get started.<\/p>\n<p>Firstly let me list out the tools and technologies used in this article.<\/p>\n<h2 class=\"wp-block-heading\">1. Tools and Technologies<\/h2>\n<ul class=\"wp-block-list\">\n<li>create-react-app CLI tool<\/li>\n<li>Node.js<\/li>\n<li>Formidable package<\/li>\n<li>Concurrently package<\/li>\n<li>Visual Studio Code IDE<\/li>\n<\/ul>\n<p>create-react-app is a command line tool from the folks who created React. This tool allows us to quickly generate the skeletal or structure upon which we can build a full blown ReactJS Application. We use it here to create the starting point of our example. We use Node.js to build a simple API which allows us to post the file we want to upload. Node.js is basically JavaScript on the server side. The formidable npm package allows us to parse and save the uploaded file. Concurrently package will allow us to launch both our client side as well as server side code simultaneously.<\/p>\n<p>Visual Studio Code IDE is my favorite IDE for JavaScript development. But feel free to use a different editor if you need to. <\/p>\n<h2 class=\"wp-block-heading\">2. Application Structure<\/h2>\n<p>First we generate our client side ReactJS application structure by executing the below command:<\/p>\n<pre class=\"brush: bash;\">&gt;npx create-react-app my-app\n<\/pre>\n<p>This command generated the following folder structure of our application.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"284\" height=\"408\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/ClientStructureFileUpload.jpg\" alt=\"ReactJS File Upload - Project Structure\" class=\"wp-image-104442\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/ClientStructureFileUpload.jpg 284w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/ClientStructureFileUpload-209x300.jpg 209w\" sizes=\"(max-width: 284px) 100vw, 284px\" \/><figcaption>Project Structure<\/figcaption><\/figure>\n<\/div>\n<p>Now let us setup our Server side API project structure. Firstly let us create a folder named api and place a single file under it named index.js. Then let us install our dependency viz., Formidable by running the below command:<\/p>\n<pre class=\"brush: bash;\">\/api&gt;npm i formidable\n<\/pre>\n<p>This will install our dependency and also save it in the newly created package.json file. Now the structure of our server side project should look like below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"279\" height=\"259\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/ServerSideStructureFileUpload.jpg\" alt=\"\" class=\"wp-image-104444\"\/><figcaption>Project Structure<\/figcaption><\/figure>\n<\/div>\n<p>We are not set and good to go with both our client side and server side application structure set up. Next let us start working on our client side application.<\/p>\n<h2 class=\"wp-block-heading\">3. Client Side Application<\/h2>\n<p>We will write two components to achieve the File uploading functionality. One would be a ProgressBar component that takes as its props the percentage of completion. Second the FileUpload component that renders an input tag of type file. We hide this input and instead show a button. On the click of this button we simulate a click on the file input. This in turn triggers the select file dialog. Once the user selects file(s) we process them and post them to our server side API. The code for our simple Progress Bar component looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>ProgressBar.js<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush: js;\">import&nbsp;React&nbsp;from&nbsp;'react';\n\nfunction&nbsp;ProgressBar(props)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&lt;div&nbsp;\nstyle={{&nbsp;height:&nbsp;'7px',&nbsp;\n         width:&nbsp;'220px',&nbsp;\n         backgroundColor:&nbsp;'whitesmoke'&nbsp;}}&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;\nstyle={{&nbsp;\n         height:&nbsp;'100%',&nbsp;\n         width:&nbsp;props.progress,&nbsp;\n         backgroundColor:&nbsp;'blue'&nbsp;}}&gt;&lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;;\n}\n\nexport&nbsp;default&nbsp;ProgressBar;<\/pre>\n<p>The code for our main FileUpload component looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>FileUpload.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import&nbsp;React,&nbsp;{&nbsp;useState,&nbsp;createRef&nbsp;}&nbsp;from&nbsp;'react';\nimport&nbsp;ProgressBar&nbsp;from&nbsp;'.\/ProgressBar';\n\nfunction&nbsp;FileUploader(props)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;[progress,&nbsp;setProgress]&nbsp;=&nbsp;useState(\"0%\");\n&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;files&nbsp;=&nbsp;[];\n&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;fileInput&nbsp;=&nbsp;createRef();\n&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;processFiles&nbsp;=&nbsp;()&nbsp;=&gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;request&nbsp;=&nbsp;new&nbsp;XMLHttpRequest();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setProgress(\"0%\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files&nbsp;=&nbsp;fileInput.current.files;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(files.length&nbsp;===&nbsp;0)&nbsp;return;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.upload.addEventListener(\"progress\",&nbsp;showProgress);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.open(\"POST\",&nbsp;\"\/uploadFile\",&nbsp;true);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;formData&nbsp;=&nbsp;new&nbsp;FormData();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;file&nbsp;=&nbsp;0;&nbsp;file&nbsp;&lt;&nbsp;files.length;&nbsp;file++)&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formData.append(\"file\"&nbsp;+&nbsp;file,&nbsp;\n                            files[file],&nbsp;files[file].name);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.send(formData);\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;showProgress&nbsp;=&nbsp;(evt)&nbsp;=&gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;percentage&nbsp;=&nbsp;(((evt.loaded&nbsp;\/&nbsp;evt.total)&nbsp;*&nbsp;100))&nbsp;+&nbsp;\"%\";\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setProgress(percentage);\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&lt;&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=\"file\"&nbsp;multiple={true}&nbsp;id='browser'&nbsp;\n            style={{&nbsp;display:&nbsp;'none'&nbsp;}}&nbsp;ref={fileInput}&nbsp;\n            onChange={processFiles}&nbsp;\/&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button&nbsp;\nonClick={()&nbsp;=&gt;&nbsp;{&nbsp;document.getElementById('browser').click();}}&gt;\n             Browse&lt;\/button&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ProgressBar&nbsp;progress={progress}&nbsp;\/&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{progress&nbsp;===&nbsp;\"100%\"&nbsp;&amp;&amp;&nbsp;\n             &lt;span&gt;File&nbsp;Uploaded&nbsp;Successfully!&lt;\/span&gt;}\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/&gt;\n\n}\n\nexport&nbsp;default&nbsp;FileUploader;<\/pre>\n<p>Now let us turn our attention to the server side code. <\/p>\n<h2 class=\"wp-block-heading\">4. Server Side API<\/h2>\n<p>We use the <code>http<\/code> module in Nodejs to create a basic API. We accept POST request, The API expects the request body to have files that are to be uploaded. The API places the files in the <code>\"c:\/data\/\" <\/code>folder. The code for our API looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>index.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">var&nbsp;http&nbsp;=&nbsp;require(\"http\");\nvar&nbsp;url&nbsp;=&nbsp;require(\"url\");\nvar&nbsp;fs&nbsp;=&nbsp;require(\"fs\");\nvar&nbsp;formidable&nbsp;=&nbsp;require(\"formidable\");\nvar&nbsp;port&nbsp;=&nbsp;8090;\nvar&nbsp;host&nbsp;=&nbsp;\"localhost\";\n\nhttp.createServer(function&nbsp;(req,&nbsp;res)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;path&nbsp;=&nbsp;url.parse(req.url,&nbsp;true);\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(path.pathname.endsWith(\"uploadFile\"))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;form&nbsp;=&nbsp;new&nbsp;formidable.IncomingForm();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form.parse(req,&nbsp;function&nbsp;(err,&nbsp;fields,&nbsp;files)&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;file&nbsp;in&nbsp;files)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!files.hasOwnProperty(file))&nbsp;continue;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;oldpath&nbsp;=&nbsp;files[file].path;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;newpath&nbsp;=&nbsp;`C:\/data\/${files[file].name}`;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fs.renameSync(oldpath,&nbsp;newpath);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res.write('File&nbsp;uploaded&nbsp;and&nbsp;moved!');\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res.end();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}).listen(port,&nbsp;host);<\/pre>\n<h2 class=\"wp-block-heading\">5. Running the Application<\/h2>\n<p>To run this application, we need to perform a couple of steps. First we need concurrently, we install it to the root of our application like below:<\/p>\n<pre class=\"brush: bash;\">\/&gt;npm i concurrently\n<\/pre>\n<p>Our completed project structure with both server side and client side code should now look like below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"314\" height=\"546\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/CompleteProjectStructureFileUploadReactJS.jpg\" alt=\"ReactJS File Upload - Project Structure\" class=\"wp-image-104451\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/CompleteProjectStructureFileUploadReactJS.jpg 314w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/CompleteProjectStructureFileUploadReactJS-173x300.jpg 173w\" sizes=\"(max-width: 314px) 100vw, 314px\" \/><figcaption>Project Structure<\/figcaption><\/figure>\n<\/div>\n<p>Now we need to add a command to the root package.json to launch both the API and client side code. Our root package.json file should look like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush: js;\">{\n&nbsp;&nbsp;\"name\":&nbsp;\"react-js-file-upload-example\",\n&nbsp;&nbsp;\"version\":&nbsp;\"1.0.0\",\n&nbsp;&nbsp;\"description\":&nbsp;\"\",\n&nbsp;&nbsp;\"main\":&nbsp;\"index.js\",\n&nbsp;&nbsp;\"scripts\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"start\":&nbsp;\"concurrently&nbsp;\\\"npm&nbsp;start&nbsp;--prefix&nbsp;\nmy-app\/\\\"&nbsp;\\\"npm&nbsp;start&nbsp;--prefix&nbsp;api\/\\\"\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"test\":&nbsp;\"echo&nbsp;\\\"Error:&nbsp;no&nbsp;test&nbsp;specified\\\"&nbsp;&amp;&amp;&nbsp;exit&nbsp;1\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"author\":&nbsp;\"Siddharth&nbsp;Seth\",\n&nbsp;&nbsp;\"license\":&nbsp;\"ISC\",\n&nbsp;&nbsp;\"dependencies\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"concurrently\":&nbsp;\"^5.2.0\"\n&nbsp;&nbsp;}\n}<\/pre>\n<p>Let us now run our application, using the command below:<\/p>\n<pre class=\"brush: bash;\">&gt;npm start\n<\/pre>\n<p>The output should look like below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"709\" height=\"683\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-1.jpg\" alt=\"ReactJS File Upload - Project Output\" class=\"wp-image-104452\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-1.jpg 709w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-1-300x289.jpg 300w\" sizes=\"(max-width: 709px) 100vw, 709px\" \/><figcaption>Project Output<\/figcaption><\/figure>\n<\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"684\" height=\"698\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-2.jpg\" alt=\"\" class=\"wp-image-104453\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-2.jpg 684w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-2-294x300.jpg 294w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/Project\u014cutputFileUploadReactJS-2-70x70.jpg 70w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><figcaption>Project Output<\/figcaption><\/figure>\n<\/div>\n<p>This wraps up our look at File Upload using ReactJS Example. To get the code for this example check out the section below:<\/p>\n<h2 class=\"wp-block-heading\">6. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/05\/JCG-ReactJS-File-Upload-Example.zip\"><strong>ReactJS File Upload Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We take a look at how to build a feature to upload files in a ReactJS Application. We will use the ubiquitous XMLHttpRequest Object to post the file data &hellip;<\/p>\n","protected":false},"author":82952,"featured_media":92051,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1903],"tags":[1919],"class_list":["post-104381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","tag-reactjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ReactJS File Upload Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ReactJS File Upload Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-06T10:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Siddharth Seth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Seth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html\"},\"author\":{\"name\":\"Siddharth Seth\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\"},\"headline\":\"ReactJS File Upload Example\",\"datePublished\":\"2020-05-06T10:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html\"},\"wordCount\":699,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"keywords\":[\"Reactjs\"],\"articleSection\":[\"React.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html\",\"name\":\"ReactJS File Upload Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"datePublished\":\"2020-05-06T10:00:00+00:00\",\"description\":\"In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-file-upload-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"React.js\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\\\/react-js\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"ReactJS File Upload Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\",\"name\":\"Siddharth Seth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"caption\":\"Siddharth Seth\"},\"description\":\"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/siddharth-seth-240180\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/siddharth_seth1980\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ReactJS File Upload Example - Java Code Geeks","description":"In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html","og_locale":"en_US","og_type":"article","og_title":"ReactJS File Upload Example - Java Code Geeks","og_description":"In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We","og_url":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-05-06T10:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","type":"image\/jpeg"}],"author":"Siddharth Seth","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Siddharth Seth","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html"},"author":{"name":"Siddharth Seth","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c"},"headline":"ReactJS File Upload Example","datePublished":"2020-05-06T10:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html"},"wordCount":699,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","keywords":["Reactjs"],"articleSection":["React.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html","url":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html","name":"ReactJS File Upload Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","datePublished":"2020-05-06T10:00:00+00:00","description":"In this article we build a File Upload Feature using ReactJS. ReactJS has gained ground and has become the go to library for Front end Development. We","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/reactjs-file-upload-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"React.js","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript\/react-js"},{"@type":"ListItem","position":5,"name":"ReactJS File Upload Example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c","name":"Siddharth Seth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","caption":"Siddharth Seth"},"description":"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.","sameAs":["https:\/\/www.linkedin.com\/in\/siddharth-seth-240180\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/siddharth_seth1980"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/82952"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=104381"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104381\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/92051"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=104381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=104381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=104381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}