<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Youssef Selkani</title>
    <description>The latest articles on DEV Community by Youssef Selkani (@usfslk).</description>
    <link>https://dev.to/usfslk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F129146%2F5dcd1d49-2959-4455-ab8d-e5d6211651ea.jpeg</url>
      <title>DEV Community: Youssef Selkani</title>
      <link>https://dev.to/usfslk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/usfslk"/>
    <language>en</language>
    <item>
      <title>How to upload a file to Firebase Storage in React</title>
      <dc:creator>Youssef Selkani</dc:creator>
      <pubDate>Sun, 22 Dec 2019 21:15:03 +0000</pubDate>
      <link>https://dev.to/usfslk/how-to-upload-a-file-to-firebase-storage-in-react-5f20</link>
      <guid>https://dev.to/usfslk/how-to-upload-a-file-to-firebase-storage-in-react-5f20</guid>
      <description>&lt;p&gt;First, you must have a Google account, log in to console.firebase.com then enable Storage database on your account and make sure to set up database rules, to import and use the library on your project run the command&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install firebase&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;In a separate file initialize the app using your config credentials like demonstrated below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import firebase from 'firebase/app'
import 'firebase/storage'

  const config = {
    apiKey: 'xxx-xxxx',
    authDomain: 'xxx-xxx.firebaseapp.com',
    databaseURL: 'https://xxxx-xxxx.firebaseio.com',
    projectId: 'xxxxx-xxxx',
    storageBucket: 'xxxx-xxxx.appspot.com',
    messagingSenderId: 'xxxxxxx'
  }
  const fire = firebase.initializeApp(config)
  const storage = firebase.storage()

  export { storage as default }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;From there, you start by building the user interface, we only need 3 components to handle the upload process, the first element one is an input file picker, using the accept method you can specify what file types to allow, we also give it an id so we can hide the default ugly input picker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  {done &amp;amp;&amp;amp; &amp;lt;h3&amp;gt;Uploaded successfully!&amp;lt;/h3&amp;gt;}
  {uploading &amp;amp;&amp;amp; &amp;lt;progress percent={progress}  /&amp;gt;}
    ...
  &amp;lt;input
    accept='image/x-png, image/jpeg'
    id='myfileinput'
    class='inputfile'
    type='file'
    onChange={this.handleChange}
    /&amp;gt;

    &amp;lt;label for='myfileinput'&amp;gt;
    &amp;lt;i class='ui upload icon' /&amp;gt;
    Select a file
    &amp;lt;/label&amp;gt;

    &amp;lt;button 
    onClick={this.handleUpload}&amp;gt;
    Upload
    &amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The handleChange function only return the file selected by the user and save it to the state, note that we are only using the first file selected, as you know, the input can also accept multiple files selecttion, in that case, tweak your code accordingly to make sure you are handling all selected files.&lt;/p&gt;

&lt;p&gt;See full article and video tutorial at &lt;a href="https://murkstom.com/blog/firebase-storage-tuto?utm_source=devto&amp;amp;utm_medium=storagetuto"&gt;Murkstom blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>database</category>
    </item>
  </channel>
</rss>
