Skip to content

Commit

Permalink
image uploader working
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNoIce committed Aug 5, 2019
1 parent fb2f4dc commit 87c2abc
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 109 deletions.
88 changes: 88 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"mapbox-gl": "^1.2.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-dropzone": "^10.1.7",
"react-images-upload": "^1.2.7",
"react-map-gl": "^5.0.7",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"reactstrap": "^8.0.1"
"reactstrap": "^8.0.1",
"superagent": "^5.1.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
4 changes: 2 additions & 2 deletions src/components/applicationViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import loginManager from "./modules/loginManager";
import IssueEditForm from "./issues/issueEditForm";
import IssueForm from "./issues/newIssueForm"
import "./issues/issues.css";
import Image from "./map/map"
import Image from "./imgUpload/imgUpload"
import "bootstrap/dist/css/bootstrap.min.css";


Expand Down Expand Up @@ -108,7 +108,7 @@ export default class ApplicationViews extends Component {
/>
<Route
exact
path="/map"
path="/imgUpload"
render={props => {
if (this.isAuthenticated()) {
return (
Expand Down
86 changes: 86 additions & 0 deletions src/components/imgUpload/imgUpload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { Component } from "react";
import Dropzone from "react-dropzone";
import request from "superagent";

const CLOUDINARY_UPLOAD_PRESET = "uploadCapstone";
const CLOUDINARY_UPLOAD_URL =
"https://api.cloudinary.com/v1_1/dqwaphhqv/image/upload";

class Image extends Component {
constructor(props) {
super(props);

this.state = {
uploadedFileCloudinaryUrl: ""
};
}
onImageDrop(files) {
this.setState({
uploadedFile: files[0]
});

this.handleImageUpload(files[0]);
}
handleImageUpload(file) {
let upload = request
.post(CLOUDINARY_UPLOAD_URL)
.field("upload_preset", CLOUDINARY_UPLOAD_PRESET)
.field("file", file);

upload.end((err, response) => {
if (err) {
console.error(err);
}

if (response.body.secure_url !== "") {
this.setState({
uploadedFileCloudinaryUrl: response.body.secure_url
});
}
});
}

render() {
return (
<React.Fragment>
<div>
<div className="FileUpload">
<Dropzone
onDrop={this.onImageDrop.bind(this)}
accept="image/*"
multiple={false}
>
{({ getRootProps, getInputProps }) => {
return (
<div {...getRootProps()}>
<input {...getInputProps()} />
{
<p>
Try dropping some files here, or click to select files to
upload.
</p>
}
</div>
);
}}
</Dropzone>
</div>

<div>
{this.state.uploadedFileCloudinaryUrl === "" ? null : (
<div>
<p>{this.state.uploadedFile.name}</p>
<img src={this.state.uploadedFileCloudinaryUrl} />
</div>
)}
</div>
</div>
</React.Fragment>
)
}

}



export default Image;
104 changes: 0 additions & 104 deletions src/components/map/map.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/nav/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class NavBar extends Component {
</Link>
</li>
<li className="nav-item">
<Link className="nav-link" to="/map">
Mappie
<Link className="nav-link" to="/imgUpload">
Upload Image
</Link>
</li>
</ul>
Expand Down

0 comments on commit 87c2abc

Please sign in to comment.