Last active
March 25, 2021 17:08
-
-
Save EthanBonsignori/570297cf73eac1a24e2245da30e4c608 to your computer and use it in GitHub Desktop.
Second revision of App.js - adding handleChange function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| function App() { | |
| // Placeholder, will fetch url from Database when setup | |
| const profilePictureUrl = "https://placehold.it/200x200"; | |
| const handleChange = (evt) => { | |
| const file = evt.target.files[0]; | |
| const reader = new FileReader(); | |
| reader.readAsDataURL(file); | |
| reader.onload = () => { | |
| console.log(reader.result) // log Base64 for now | |
| } | |
| reader.onerror = (err) => { | |
| console.error(err) | |
| } | |
| }; | |
| return ( | |
| <div className="App"> | |
| <h3>Profile Picture Upload</h3> | |
| <img className="profile-picture" alt="profile" src={profilePictureUrl} /> | |
| <label className="upload-label" htmlFor="upload">Change Profile Picture</label> | |
| <input | |
| id="upload" | |
| type="file" | |
| accept="image/*" // Only accept image files (.jpg, .png, .gif, etc) | |
| style={{ display: "none" }} | |
| onChange={handleChange} | |
| /> | |
| </div> | |
| ); | |
| }; | |
| export default App; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the tutorial found here: https://ethanbon.com/blog/uploading-cropped-profile-images-to-digital-ocean-spaces-1