-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
181 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 characters
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 characters
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 characters
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; |
This file was deleted.
Oops, something went wrong.
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 characters