├── .babelrc
├── .eslintrc
├── .gitignore
├── .npmignore
├── LICENSE
├── changelog.md
├── package.json
├── readme.md
├── s3router.js
├── src
├── DropzoneS3Uploader.js
└── index.js
└── test
├── .env
├── mocha.opts
└── todo.tests.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "stage": 0,
3 | "loose": "all",
4 | }
5 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "founderlab"
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | .tmp/
4 | bower_components/
5 | node_modules/
6 | npm-debug.log
7 | /lib
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | .tmp/
4 | bower_components/
5 | node_modules/
6 | npm-debug.log
7 | .babelrc
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 founderlab
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 |
2 | ## [Unreleased]
3 |
4 | ## [1.0.0]
5 | - PropTypes via the prop-types package (thanks @13colours).
6 |
7 | ## [1.0.0-rc.3]
8 | - Fixed a bug with file url creation (thanks @davidascher).
9 | - Fixed a build error caused by babel picking up the wrong config.
10 |
11 | ## [1.0.0-rc.2]
12 | - The prop `upload` is used to specify options for `react-s3-uploader` (replaces `uploaderOptions`).
13 | - Readme is better.
14 |
15 | ## [1.0.0-rc.1]
16 | - Refactoring to clean up this abomination.
17 | - Props have been cleaned up.
18 | - Other props are pased to `react-dropzone`.
19 | - The `fileUrls` and `filenames` props have been replaced by `uploadedFile` objects. Each `uploadedFile` object has the filename, full s3 url (as `fileUrl`) and a reference to the original file descriptor from the upload.
20 | - Children have state information passed again via the `uploadedFiles` prop.
21 | - Passing children props can be disabled by setting the `passChildrenProps` prop to false to avoid React warnings about unused props.
22 |
23 | ## [0.11.0]
24 | - Upgraded react-s3-uploader to ^4.0.0
25 |
26 | ## [0.10.0]
27 | - Removed underscored props in favour of camelCase only.
28 |
29 | ## [0.9.0]
30 | - Upgraded `react-s3-uploader` to v3.3.0
31 | - Added some props: `uploaderOptions` and `preprocess`
32 |
33 | ## [0.8.1]
34 | - Fix bug caused by using _.map without importing it
35 |
36 | ## [0.8.0]
37 | - props.children no longer receive the `fileUrl`, `s3Url`, `filename`, `progress`, `error`, `imageStyle` props. If the `fileComponent` prop is specified it will receive these props.
38 | - maxFileSize and minFileSize are passed to the `react-dropzone` component, which handles validation
39 | - multiple files are handled better. Props named `fileUrls` and `filenames` are passed to the `fileComponent`, with an entry per file uploaded.
40 |
41 | ## [0.7.3]
42 | - Accepts an prop named `onDrop`, a function to be called with the files object when files are dropped.
43 |
44 | ## [0.7.0]
45 | - Removed dependency on react-bootstrap
46 | - New props:
47 | - `progressComponent`, a react component to render progress. Is provided a prop called `progress` with the current uploader progress percentage as an int (0-100).
48 | - `fileComponent` prop to do the same for rendering an uploaded file (not an image).
49 | - `isImage` a function that should return true if a filename represents an image. Default is `filename => filename && filename.match(/\.(jpeg|jpg|gif|png|svg)/i)`
50 | - If a child component is present it's only passed these props: `fileUrl, s3Url, filename, progress, error, imageStyle`
51 |
52 | ## [0.5.3]
53 | - Update React dependecy to include 15.x.x
54 |
55 | ## [0.5.0]
56 | - react-bootstrap dependency updated to ^0.29.0
57 |
58 | ## [0.4.2]
59 | - Renamed `host` option to `server` to match react-s3-uploader
60 |
61 | ## [0.4.1]
62 | - Pass accept prop to Dropzone
63 |
64 | ## [0.4.0]
65 | - Supports a display component via a child element.
66 |
67 | ## [0.3.1]
68 | - readme
69 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-dropzone-s3-uploader",
3 | "version": "1.1.0",
4 | "description": "Drag and drop s3 file uploader via react-dropzone + react-s3-uploader",
5 | "main": "lib/index.js",
6 | "author": {
7 | "name": "Gwilym Humphreys",
8 | "url": "https://github.com/gwilymhumphreys"
9 | },
10 | "license": "MIT",
11 | "repository": {
12 | "type": "git",
13 | "url": "https://github.com/founderlab/react-dropzone-s3-uploader"
14 | },
15 | "scripts": {
16 | "prepublish": "rm -rf ./lib && babel ./src --ignore '/node_modules/' --out-dir ./lib",
17 | "build": "rm -rf ./lib && babel ./src --ignore '/node_modules/' --out-dir ./lib",
18 | "watch": "rm -rf ./lib && babel ./src --ignore '/node_modules/' --watch --out-dir ./lib",
19 | "test": "eval $(cat test/.env) mocha test/**/*.tests.js"
20 | },
21 | "dependencies": {
22 | "prop-types": "^15.5.8",
23 | "react-dropzone": "^4.0.0",
24 | "react-s3-uploader": "4.5.0"
25 | },
26 | "devDependencies": {
27 | "babel": "^5.6.14",
28 | "babel-core": "^5.6.15",
29 | "babel-eslint": "^4.1.3",
30 | "eslint": "^1.5.1",
31 | "eslint-config-founderlab": "^0.1.0",
32 | "eslint-plugin-react": "^3.4.2",
33 | "expect": "^1.12.2"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Drag and drop s3 file uploader for React
2 |
3 | This component uploads files dropped into [react-dropzone](https://github.com/okonet/react-dropzone) to s3 with [react-s3-uploader](https://github.com/odysseyscience/react-s3-uploader).
4 |
5 | For more detailed docs see the source packages
6 | - [react-dropzone](https://github.com/okonet/react-dropzone)
7 | - [react-s3-uploader](https://github.com/odysseyscience/react-s3-uploader)
8 |
9 |
10 |
11 | ## Usage (client)
12 |
13 |
14 | #### Available props
15 |
16 | `s3Url` and `upload` are the only props that require configuration. All others have sensible defaults that may be overridden.
17 |
18 |
19 | Prop | Type | Description
20 | ----------------- | ----------------- | -------------------------------------------
21 | s3Url | string.isRequired | The url of your s3 bucket (`https://my-bucket.s3.amazonaws.com`)
22 | upload | object.isRequired | Upload options passed to react-s3-uploader. See [react-s3-uploader](https://github.com/odysseyscience/react-s3-uploader) for available options. Don't set `onProgress`, `onError` or `onFinish` here - use the ones below
23 | filename | string | Used as the default value if present. Filename of an image already hosted on s3 (i.e. one that was uploaded previously)
24 | notDropzoneProps | array | A list of props to *not* pass to `react-dropzone`
25 | isImage | func | A function that takes a filename and returns true if it's an image
26 | imageComponent | func | Component used to render an uploaded image
27 | fileComponent | func | Component used to render an uploaded file
28 | progressComponent | func | Component used to render upload progress
29 | errorComponent | func | Component used to render an error
30 | children | node \|\| func | If present the above components will be ignored in favour of the children
31 | passChildrenProps | bool | If true we pass the current state to children of this component. Default is true. Set to false to avoid React warnings about unused props.
32 | onDrop | func | Called when a file is dropped onto the uploader
33 | onError | func | Called when an upload error occurs
34 | onProgress | func | Called when a chunk has been uploaded
35 | onFinish | func | Called when a file has completed uploading. Called once per file if multi=true
36 | ...rest | | All other props are passed on to the `react-dropzone` component
37 |
38 |
39 | #### Example
40 | ```javascript
41 | import DropzoneS3Uploader from 'react-dropzone-s3-uploader'
42 |
43 | export default class S3Uploader extends React.Component {
44 |
45 | handleFinishedUpload = info => {
46 | console.log('File uploaded with filename', info.filename)
47 | console.log('Access it on s3 at', info.fileUrl)
48 | }
49 |
50 | render() {
51 | const uploadOptions = {
52 | server: 'http://localhost:4000',
53 | signingUrlQueryParams: {uploadType: 'avatar'},
54 | }
55 | const s3Url = 'https://my-bucket.s3.amazonaws.com'
56 |
57 | return (
58 |
{file.name}
88 |