Last active
August 20, 2020 11:09
Revisions
-
matias220510 revised this gist
Aug 20, 2020 . 1 changed file with 70 additions and 16 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,62 @@ import React from "react"; import styled from "styled-components"; const FormContainer = styled.div` min-height: 100vh; display: flex; align-items: center; flex-direction: column; justify-content: space-evenly; align-items: center; background: #642b73; /* fallback for old browsers */ background: -webkit-linear-gradient( to right, #c6426e, #642b73 ); /* Chrome 10-25, Safari 5.1-6 */ background: linear-gradient( to right, #c6426e, #642b73 ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ .imageContainer { display: flex; align-items: center; img { border-radius: 20px; margin: 20px; } } `; const FormElement = styled.form` width: 380px; background: #ff6f61; border-radius: 6px; box-shadow: 0 4px 24px -2px rgba(18, 22, 33, 0.1); position: relative; fieldset { border: none; } .uploadInput { cursor: pointer; display: inline-block; color: #fff; text-transform: uppercase; padding: 11px 20px; border: none; } `; const UploadImage = () => { const handleOnChange = async ({ target }) => { const { files } = target; const data = new FormData(); data.append("file", files[0]); data.append("upload_preset", "cloudinary_test"); const res = await fetch( "https://api.cloudinary.com/v1_1/duec6t3rs/image/upload", @@ -14,26 +65,29 @@ const UploadImage = () => { body: data, } ); console.log(res); }; return ( <div> <FormContainer> <FormElement> <fieldset> <label htmlFor="file"> <input type="file" id="file" className="uploadInput" name="file" placeholder="Upload an image" required onChange={handleOnChange} /> </label> </fieldset> </FormElement> </FormContainer> </div> ); }; -
matias220510 revised this gist
Aug 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import React from "react"; const UploadImage = () => { const handleOnChange = async ({ target }) => { -
matias220510 created this gist
Aug 18, 2020 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ import React, { useState } from "react"; const UploadImage = () => { const handleOnChange = async ({ target }) => { const { files } = target; const data = new FormData(); data.append("file", files[0]); data.append("upload_preset", "upload_test"); const res = await fetch( "https://api.cloudinary.com/v1_1/duec6t3rs/image/upload", { method: "POST", body: data, } ); const { secure_url, eager } = await res.json(); console.log(secure_url, eager); }; return ( <div> <fieldset> <label htmlFor="file"> <input type="file" id="file" className="uploadInput" name="file" placeholder="Upload an image" required onChange={handleOnChange} /> </label> </fieldset> </div> ); }; export default UploadImage;