Giter VIP home page Giter VIP logo

react-dropzone-s3-uploader's Introduction

Drag and drop s3 file uploader for React

This component uploads files dropped into react-dropzone to s3 with react-s3-uploader.

For more detailed docs see the source packages

Usage (client)

Available props

s3Url and upload are the only props that require configuration. All others have sensible defaults that may be overridden.

Prop Type Description
s3Url string.isRequired The url of your s3 bucket (https://my-bucket.s3.amazonaws.com)
upload object.isRequired Upload options passed to react-s3-uploader. See react-s3-uploader for available options. Don't set onProgress, onError or onFinish here - use the ones below
filename string Used as the default value if present. Filename of an image already hosted on s3 (i.e. one that was uploaded previously)
notDropzoneProps array A list of props to not pass to react-dropzone
isImage func A function that takes a filename and returns true if it's an image
imageComponent func Component used to render an uploaded image
fileComponent func Component used to render an uploaded file
progressComponent func Component used to render upload progress
errorComponent func Component used to render an error
children node || func If present the above components will be ignored in favour of the children
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.
onDrop func Called when a file is dropped onto the uploader
onError func Called when an upload error occurs
onProgress func Called when a chunk has been uploaded
onFinish func Called when a file has completed uploading. Called once per file if multi=true
...rest All other props are passed on to the react-dropzone component

Example

import DropzoneS3Uploader from 'react-dropzone-s3-uploader'

export default class S3Uploader extends React.Component {

  handleFinishedUpload = info => {
    console.log('File uploaded with filename', info.filename)
    console.log('Access it on s3 at', info.fileUrl)
  }

  render() {
    const uploadOptions = {
      server: 'http://localhost:4000',
      signingUrlQueryParams: {uploadType: 'avatar'},
    }
    const s3Url = 'https://my-bucket.s3.amazonaws.com'

    return (
      <DropzoneS3Uploader
        onFinish={this.handleFinishedUpload}
        s3Url={s3Url}
        maxSize={1024 * 1024 * 5}
        upload={uploadOptions}
      />
    )
  }
}

Custom display component

Specify your own component to display uploaded files. Passed a list of uploadedFile objects.

// elsewhere
class UploadDisplay extends React.Component {
  
  renderFileUpload = (uploadedFile, i) => {
    const {
      filename,   // s3 filename
      fileUrl,    // full s3 url of the file
      file,       // file descriptor from the upload
    } = uploadedFile

    return (
      <div key={i}>
        <img src={fileUrl} />
        <p>{file.name}</p>
      </div>
    )
  }

  render() {
    const {uploadedFiles, s3Url} = this.props
    return (
      <div> 
        {uploadedFiles.map(this.renderFileUpload)}
      </div>
    )
  }
}

// back in your uploader...
class S3Uploader extends React.Component {

  //...

  render() {
    return (
      <DropzoneS3Uploader 
        onFinish={this.handleFinishedUpload} 
        upload={uploadOptions}
      >
        <UploadDisplay />
      </DropzoneS3Uploader>
    )
  }
}

Usage (server)

  • Use s3Router from react-s3-uploader to get signed urls for uploads.
  • react-dropzone-s3-uploader/s3router can be used as an alias for react-s3-uploader/s3router.
  • See react-s3-uploader for more details.
app.use('/s3', require('react-dropzone-s3-uploader/s3router')({
  bucket: 'MyS3Bucket',                           // required
  region: 'us-east-1',                            // optional
  headers: {'Access-Control-Allow-Origin': '*'},  // optional
  ACL: 'private',                                 // this is the default - set to `public-read` to let anyone view uploads
}));

react-dropzone-s3-uploader's People

Contributors

13ogrammer avatar akronix avatar anaumov avatar bfcoder avatar costajohnt avatar davidascher avatar goodanthony avatar gwilymhumphreys avatar ilyakatz avatar luisherranz avatar pongsakornsemsuwan avatar restuta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-dropzone-s3-uploader's Issues

react-s3-uploader dependencies

Any reason for the react-s3-uploader not to have a ^ and use "^4.5.0" so updates can be used? Or at least a ~ to get bug fixes. "4.8.0" is the current version.

 "dependencies": {
    "prop-types": "^15.5.8",
    "react-dropzone": "^4.0.0",
    "react-s3-uploader": "4.5.0"
  },

Weird failures with latest build

Trying to upgrade to 1.0.0-rc.2, and in my CRA app, I'm getting weird failures:

[1] Starting the development server...
[1] 
[1] Failed to compile.
[1] 
[1] Error in ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js
[1] Module not found: 'react-transform-catch-errors' in /Users/da/src/participedia/frontend/node_modules/react-dropzone-s3-uploader/lib
[1] 
[1]  @ ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js 3:34-73
[1] 
[1] Error in ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js
[1] Module not found: 'redbox-react' in /Users/da/src/participedia/frontend/node_modules/react-dropzone-s3-uploader/lib
[1] 
[1]  @ ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js 11:19-42
[1] 
[1] Compiling...
[1] Failed to compile.
[1] 
[1] Error in ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js
[1] Module not found: 'react-transform-catch-errors' in /Users/da/src/participedia/frontend/node_modules/react-dropzone-s3-uploader/lib
[1] 
[1]  @ ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js 3:34-73
[1] 
[1] Error in ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js
[1] Module not found: 'redbox-react' in /Users/da/src/participedia/frontend/node_modules/react-dropzone-s3-uploader/lib
[1] 
[1]  @ ./~/react-dropzone-s3-uploader/lib/DropzoneS3Uploader.js 11:19-42
[1] 

I'll dig in a bit more, but I figured I'd flag early given that it's an RC.

Why these childProps?

When I use this (awesome btw) component with something like:

      <div style={box}>
        <DropzoneS3Uploader onFinish={this.handleFinishedUpload} {...uploaderProps}>
          <div style={legend}>
            Drop an image on here or click to select
          </div>
        </DropzoneS3Uploader>
      </div>

the rendered component looks fine, but React complains:

Warning: Unknown props `fileUrl`, `s3Url`, `filename`, `progress`, `error`, `imageStyle` on <div> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop

Which makes some sense.

Digging in, I see this line, which maybe makes sense for the FileComponent path, but I don't think it makes sense for the this.props.children path.

I'm happy to submit a PR if I'm not missing a scenario.

How to add Authentication to header ?

How can I add authorization to the header as Authorization: "token 1341sfsdf23rt..."

import DropzoneS3Uploader from "react-dropzone-s3-uploader";

   const uploadOptions = {
    server:'http://192.168.1.205/,
    signingUrl: signedUrl,
    signingUrlQueryParams: { uploadType: "avatar" }
  };


<DropzoneS3Uploader
       onFinish={handleFinishedUpload}
        upload={uploadOptions}
        s3Url={s3Url}
        filename={filename}
        onProgress={onProgress}
      >

DropzoneS3Uploader gives UploadError:404 after successful signed URL request

I'm building a serverless React app (using npm for development), that uses DropzoneS3Uploader to upload images to S3. I'm configuring it to use API Gateway (backed by Lambda) to request a signed URL before uploading a file to an S3 bucket

const uploadOptions = {
s3Path: '//',
signingUrl: 'https://.eu-west-1.amazonaws.com/Prod/',
signingUrlMethod: 'POST',
accept: 'image/*',
autoUpload: true
};

The render method goes on to return component as follows...

When this is executed it manages to generate the signed URL fine..

Request URL: https://.eu-west-1.amazonaws.com/Prod/?objectName=&contentType=image%2Fjpeg Request Method: POST Status Code: 200

{"signed_url":"https://.eu-west-1.amazonaws.com/<some_image.jpg>?X-Amz-Algorithm=AWS4-HMAC-....X-Amz-Signature=...&X-Amz-SignedHeaders=host"}

However it goes straight from that into a 404 (stacktrace below). I'm starting to wonder if npm tries to cache the image as a temp file? Whatever the problem it cant seem to reference the server/image during the PUT request to S3...

Request URL: http://localhost:3000/undefined Request Method: PUT Status Code: 404 Not Found

http://localhost:3000/undefined 404 (Not Found) ./node_modules/react-dropzone-s3-uploader/node_modules/react-s3-uploader/s3upload.js.S3Upload.uploadToS3 @ s3upload.js:171 (anonymous) @ s3upload.js:108 XMLHttpRequest.send (async) ./node_modules/react-dropzone-s3-uploader/node_modules/react-s3-uploader/s3upload.js.S3Upload.executeOnSignedUrl @ s3upload.js:113 ./node_modules/react-dropzone-s3-uploader/node_modules/react-s3-uploader/s3upload.js.S3Upload.uploadFile @ s3upload.js:178 (anonymous) @ s3upload.js:53 ...

There is a 'server' option as part of the DropzoneS3Uploader upload options. Leave it blank and i get this error, populate it with someone else and it replaces error with whatever server URL I mention. As mentioned, I plan to run this serverless so dont have a server to mention.

I switch to Dropzone and use axios and it works ok, so am wondering if DropzoneS3Uploader is just abstracting too much of the implementation code away to allow this behaviour to be controlled?

Thanks!

Error uploading files with invalid characters

When uploading files with invalid characters, the upload fails with this error

invalid filename

The onError method is not called so there's no way to give an error message that the string is incorrect. The react-s3-uploader has a scrubFilename method which I believe is intended for issues like this. It will be great if this props or something similar is added for issues like this.

Cannot get it to work with Meteor

Hi, first of all, sorry for putting this under "issue". This is more of a cry for help.
Do you guys have this working with Meteor? For some reason I kept getting the "net::ERR_CONNECTION_CLOSED" error when calling the backend to retrieve that signed URL. It's as if the server route doesn't exist.
Some newbie questions:

  1. Does one have to specify the "server" in uploaderProps even if it's under the same domain?
  2. What are some ways to debug where in the chain this broke?

Here's my code:

Client-side:
`render() {
const style = {
height: 200,
border: 'dashed 2px #999',
borderRadius: 5,
position: 'relative',
cursor: 'pointer',
};

    const uploaderProps = {
        style,
        maxFileSize: 1024 * 1024 * 50,
        server: 'https://localhost:3000',
        s3Url: 'https://outfit-generator.s3.amazonaws.com/',
        signingUrlQueryParams: {uploadType: 'avatar'},
    };

    return (
        <DropzoneS3Uploader onFinish={this.handleFinishedUpload} {...uploaderProps} />
    )
}`

Server-side:
`import { Meteor } from 'meteor/meteor';
import express from 'express';

import { MAILGUN_URL, AWSAccessKeyId, AWSSecretKey } from './secrets';

Meteor.startup(() =>
{
process.env.AWSAccessKeyId = AWSAccessKeyId;
process.env.AWSSecretKey = AWSSecretKey;
process.env.AWS_ACCESS_KEY_ID = AWSAccessKeyId;
process.env.AWS_SECRET_ACCESS_KEY = AWSSecretKey;

let app = express();

app.use('/s3',
    require('react-dropzone-s3-uploader/s3router')(
        {
            bucket: 'outfit-generator',
            headers: {'Access-Control-Allow-Origin': '*'}, // optional
            ACL: 'private' // this is default
        }
    )
);

});`

Many thanks.
JJ

multiple uploads qued

Hi i am working on a video upload component.In here it takes a while to upload a video so there is a risk of loosing all data if everythng is uploaded at once.So is there a way to make it upload one by one in a waiting queue so that at least few videos are uploaded if theres any issue coming and have to loose all uploaded progress?

The request signature we calculated does not match the signature you provided. Check your key and signing method.

Hi there.

I'm getting The request signature we calculated does not match the signature you provided. Check your key and signing method. back from AWS when trying to submit files. I'm on version 0.7.3.

Any ideas what may be happening?

Here's my setup:

express:

  app.use('/s3', require('react-dropzone-s3-uploader/s3router')({
    bucket: "my-queue-name",
    region: 'us-east-1',
    signatureVersion: 'v4', 
    headers: {'Access-Control-Allow-Origin': '*'}, 
    ACL: 'private',
  }));

react:


		const style = {
			className: "uploadNew"
		}

		const uploaderProps = {
			style, 
			server: 'http://localhost:3000', 
			s3Url: 'https://dotbc-queue.s3.amazonaws.com/', 
			signingUrl: "/s3/sign",
			uploadRequestHeaders: { 'x-amz-acl': 'public-read' },
			contentDisposition: "auto",
		}

    return (
		<div className="filesDocs">
			<label>Files & Documents</label>
			<div className="uploaded">
				<ul className="unstyled">
					

					
				</ul>
			</div>
			<DropzoneS3Uploader {...uploaderProps}>

Here's the complete error I'm getting back. I notice the CanonicalRequest is labeled as UNSIGNED-PAYLOAD. Not sure if that's indicative of what's going on...

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
<AWSAccessKeyId>AKIAI7O2H3HADOMOS3MA</AWSAccessKeyId>
<StringToSign>
AWS4-HMAC-SHA256 20161114T033436Z 20161114/us-east-1/s3/aws4_request 41fe70bff8e3ba4abbcb046361064f9a8dab17cd2b4de89d640a23f0e4a9268c
</StringToSign>
<SignatureProvided>
5dc341cd1d9d240be19cc9284aee38fbe00c93c54743dbf7f2c98740bb82d396
</SignatureProvided>
<StringToSignBytes>
41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 36 31 31 31 34 54 30 33 33 34 33 36 5a 0a 32 30 31 36 31 31 31 34 2f 75 73 2d 65 61 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 34 31 66 65 37 30 62 66 66 38 65 33 62 61 34 61 62 62 63 62 30 34 36 33 36 31 30 36 34 66 39 61 38 64 61 62 31 37 63 64 32 62 34 64 65 38 39 64 36 34 30 61 32 33 66 30 65 34 61 39 32 36 38 63
</StringToSignBytes>
<CanonicalRequest>
GET /28fad916-9cee-4116-93aa-f80461d77e41_Getting_Started.rtf Content-Type=text%2Frtf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI7O2H3HADOMOS3MA%2F20161114%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20161114T033436Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host%3Bx-amz-acl&x-amz-acl=private host:dotbc-queue.s3.amazonaws.com x-amz-acl:private host;x-amz-acl UNSIGNED-PAYLOAD
</CanonicalRequest>
<CanonicalRequestBytes>
47 45 54 0a 2f 32 38 66 61 64 39 31 36 2d 39 63 65 65 2d 34 31 31 36 2d 39 33 61 61 2d 66 38 30 34 36 31 64 37 37 65 34 31 5f 47 65 74 74 69 6e 67 5f 53 74 61 72 74 65 64 2e 72 74 66 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3d 74 65 78 74 25 32 46 72 74 66 26 58 2d 41 6d 7a 2d 41 6c 67 6f 72 69 74 68 6d 3d 41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 26 58 2d 41 6d 7a 2d 43 72 65 64 65 6e 74 69 61 6c 3d 41 4b 49 41 49 37 4f 32 48 33 48 41 44 4f 4d 4f 53 33 4d 41 25 32 46 32 30 31 36 31 31 31 34 25 32 46 75 73 2d 65 61 73 74 2d 31 25 32 46 73 33 25 32 46 61 77 73 34 5f 72 65 71 75 65 73 74 26 58 2d 41 6d 7a 2d 44 61 74 65 3d 32 30 31 36 31 31 31 34 54 30 33 33 34 33 36 5a 26 58 2d 41 6d 7a 2d 45 78 70 69 72 65 73 3d 36 30 26 58 2d 41 6d 7a 2d 53 69 67 6e 65 64 48 65 61 64 65 72 73 3d 68 6f 73 74 25 33 42 78 2d 61 6d 7a 2d 61 63 6c 26 78 2d 61 6d 7a 2d 61 63 6c 3d 70 72 69 76 61 74 65 0a 68 6f 73 74 3a 64 6f 74 62 63 2d 71 75 65 75 65 2e 73 33 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 72 69 76 61 74 65 0a 0a 68 6f 73 74 3b 78 2d 61 6d 7a 2d 61 63 6c 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 44
</CanonicalRequestBytes>
<RequestId>B81DDBE145ECAA39</RequestId>
<HostId>
l+kVUQMe4jrC8EM88iML42PLRxiKhG1XmxdFkEt9k7C8lPbVmlsTQURN3ZFRe7FoEe+9IcK7g48=
</HostId>
</Error>

using onDrop function stops the s3 upload process

I tried using the onDrop function and get a set of uploading file objetcs in a table layout but after using it the progress of uploading never starts

<DropzoneS3Uploader upload={uploadOptions} onFinish={handleUploads} onProgress={e => console.log(e)} onDrop={e => console.log(e)} accept="video/*" s3Url={s3Url} > <UploadDisplay /> </DropzoneS3Uploader>

this is an unusual case since this is a direct function to work with but I experience it has an issue for sure and to see the outputs I will upload the 2 scenarios

Without using onDrop
image

using onDrop
image

any clues to sort this out?

Multiple uploads

I'm not quite sure how you've implemented multiple uploads? As far as I can tell, onFinish only get's called once, even if multiple images have been dragged into the component. So how do you handle that?
The react-dropzone component stores the files in state, where you then can loop through them onDrop

Readme proposal

It is not really a bug or an issue, but I wanted to propose, that you mention in the docs, that the 'progressComponent' is also the component holding the dropzone-area when not actively uploading, and not having any children.
Took us quiet a while to figure this out and would've really helped if it was mentioned in the props descriptions.
Thank you :)

XHR error on mobile

Hey guys, has anybody tested this on mobile?
Deployed. Added the address to S3's CORS profile. Works perfectly on a desktop browser. Fails on mobile with "XHR error".

Bug or what am I missing information from upload options?

Disclaimer I'm not using the react-s3-uploader function to get the signed URL. I have a different API through the serverless framework.

serverless code

import json
import logging
import os
import boto3
import sys
import mimetypes
dynamodb = boto3.resource('dynamodb')
s3 = boto3.client('s3')

from model import validate_and_clean, generate


def signedUrl(event, context):
    data = event['queryStringParameters']
    object_name = data.get(u'objectName')
    content_type = data.get(u'contentType',mimetypes.guess_type(object_name)[0])
    signed_url = s3.generate_presigned_url(
        'put_object', 
        Params={
        'Bucket':'<BUCKET>',
        'Key': object_name,
        },
        ExpiresIn = 300
    )

    obj = {
        'signedUrl': signed_url,
        'publicUrl' : '/s3/uploads/' + object_name,
        'filename': object_name,
        'fileKey': object_name
    }

    response = {
        'headers': {'Access-Control-Allow-Origin': '<DOMAIN>'},
        "statusCode": 200,
        "body" : json.dumps({
            "data": obj,
            "errors" : [],
            "success": True
        })
    }
    return response

React code

import Dropzone from 'react-dropzone-s3-uploader';
//...
class renderArtDropzoneInput extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      files: [],
    };
    this.onFinish = this.onFinish.bind(this);
  }

  onFinish(acceptedFiles, rejectedFiles) {
    this.props.input.onChange(acceptedFiles);

    this.setState({
      files: acceptedFiles,
    });
  }

  onOpenClick() {
    this.dropzone.open();
  }

  handleFinishedUpload = info => {
    console.log('File uploaded with filename', info.filename)
    console.log('Access it on s3 at', info.fileUrl)
  }

  render() {
    const uploadOptions = {
      server: 'https://####.execute-api.us-west-2.amazonaws.com/beta',
      signingUrlQueryParams: {uploadType: 'avatar'},
      s3Url: 'https://####.s3-us-west-2.amazonaws.com'
    }
    const s3Url = 'https://####.s3-us-west-2.amazonaws.com'

    return (
      <Dropzone
        ref={(node) => { this.dropzone = node; }}
        s3url={s3Url}
        multiple={false}
        onFinish={this.onFinish}
        maxSize={1024 * 1024 * 5}
        upload={uploadOptions}/>
    )
  }
}

I end up getting an error:

s3upload.js:171

PUT http://localhost:3000/user/artist/undefined 404 (Not Found)
  | ./node_modules/react-s3-uploader/s3upload.js.S3Upload.uploadToS3 | @ | s3upload.js:171

I'm not sure how it properly uses the server setting to get the signedUrl from the server but somehow is using the current react application's url for the PUT action to upload the file.

package.json (i had react dropzone installed before trying your lib not sure if this matters)

    "react-dropzone": "^4.1.3",
    "react-dropzone-s3-uploader": "^1.1.0",

Manual upload

Does anyone know how to pass a ref to react-s3-uploader through the dropzone?

Multiple files preview

How is the component supposed to handle displaying multiple files/images? If it only accepts ONE fileUrl, then what is the purpose of multiple file uploads?

Uploaded File Path

Hi,

I'm thinking of using the library but I cant understand how to get the uploaded file path in s3 after the uploading.

I've tested it a little and the onFinish action is triggered with the signingUrl.

Can you please help?

Client custom headers

Unless I'm missing something, it doesn't seem possible to add custom headers to the signing servers. How could I request a signing URL to my server using an authorization header?

Props for custom component

In your README is written: Specify your own display for an uploaded file. Will receive these props: {fileUrl, s3Url, filename, progress, error, imageStyle}, but it never does. Check your code, childProps are passed only to FileComponent (which is not documented at all). These values are never passed to DropzoneS3Uploader children.

How to display text inside dropzone?

How to display any text inside the dropzone and don't break onProgress function?

<DropzoneS3Uploader
        onFinish={this.handleFinishedUpload}
        s3Url={s3Url}
        maxSize={1024 * 1024 * 5}
        upload={uploadOptions}
>
     <p>Try dropping some files here, or click to select files to upload.</p>
</DropzoneS3Uploader>

adding <p> paragraph blocks somehow progress dispaly and also casues that after successful upload filename is not displayed inside the drop zone.

Basically I'd love to have something like that
image

How can I display text inside the dropzone and also have progress info and file name after the upload completes?

Passing onDrop prop ensures handleDrop method will not be called

If DropzoneS3Uploader is given an onDrop callback, it will be present in the dropzoneProps const in the component's render method.

In render, when the Dropzone component is returned, it is given an onDrop property set to this.handleDrop, but then spreads the dropzoneProps, which will have an onDrop key. This means that onDrop={this.handleDrop} will always be replaced when the onDrop property exists.

This makes it strange that the handleDrop method checks the presence of and invokes this.props.onDrop.

Is the onDrop prop is supposed to fully replace handleDrop, or be called at the end of handleDrop? From my read on it, the latter can never happen.

Removing previews

Currently I don't see how it would be possible to let the user remove an item once it has been dragged into the dropzone area.

Dropzone supports addRemoveLinks. Any hint on how this could be used from react-dropzone-s3-uploader?

Custom progress component

It would be great if there was a way to pass in custom progress element. Currently, I would need to require the full react-bootstrap just to get a progress bar

How do I explicitly pass the AWS Access Key Id?

I am using an express server.

app.use('/s3', require('react-dropzone-s3-uploader/s3router')({
  bucket: my-s3-bucket',
  region: 'us-east-1',
  headers: { 'Access-Control-Allow-Origin': '*' },
  ACL: 'public-read',
}))

The issue is that the url is missing the AWSAccessKeyId query parameter (see below)

https://s3.amazonaws.com/my-s3-bucket/fjdshjsklfhsadhfdshf_spiderman.jpg?AWSAccessKeyId=&Content-Type=image%2Fjpeg&Expires=1516309866&Signature=&x-amz-acl=public-read

I have this listed in my .env file

REACT_APP_AWS_ACCESS_KEY_ID="ABUNCHOFLETTERS"
REACT_APP_AWS_SECRET_ACCESS_KEY="ABUNCHOFLETTERSANDNUMBERS12345"
AWS_ACCESS_KEY_ID="ABUNCHOFLETTERS"
AWS_SECRET_ACCESS_KEY="ABUNCHOFLETTERSANDNUMBERS12345"

Does anyone have any suggestions?

s3uploader file info - missing filename - onFinish returns /undefined

react-dropzone component expects filename in info returned by s3uploader component. The preprocess function doesn't return filename in the info object, only name.
onFinish returns /undefined file

S3Upload.prototype.preprocess = function(file, next) {
console.log('base.preprocess()', file);
return next(file);
};

returns

File(16991) {preview: "blob:http://localhost:3000/f6e4d946-e01c-4b8e-8986-ccb813265d4d", name: "Screen Shot 2018-05-07 at 20.36.24.png", lastModified: 1525714585346, lastModifiedDate: Mon May 07 2018 20:36:25 GMT+0300 (EEST), webkitRelativePath: "", …}

How to specify path of upload

I am trying to get the file uploaded into a path such as this:

/folder1/folder2/filename.jpg

I am passing in an s3Url such as this:

const s3Url = 'https://s3.us-west-1.amazonaws.com/mybucket/'; const path = 'folder1/folder2'; ... <DropzoneS3Uploader onFinish={this.handleFinishedUpload} s3Url={s3Url} maxSize={1024 * 1024 * 5} upload={{s3path: path}} />

What this is doing is adding the file but it is adding the unique id stuff (that s3 prepends to the url) to the first folder:

/iweufhwe_folder1/folder2/filename.jpg

Whereas I would like it to be:

/folder1/folder2/iweufhwe_filename.jpg

Duplicate Files

Hey there,

Unsure if this issue is caused by issues with the onDrop prop callback. I was using the onDrop prop to check for duplicate files (I store an array in state to check for duplicates) until I realised that the onDrop call would prevent the component from continuing thus no uploads would occur.

I then tried to put the same duplicate check in the s3-uploader preprocess prop call, I'm able to have minor success via the next(file) method, however when I hit a duplicate I can't simply skip that file by not calling next(file), as it then cancels uploads for all further files in that drop.

Is there something I'm missing to achieve this?

Many thanks

CORS error (no permissions)

I am trying to upload photos through the react-dropzone-s3-uploader but I am not sure how to give access to the bucket. I get a CORS error and a 403 forbidden.

This is what I have so far

const handleFinishedUpload = (info) => {
    console.log("File uploaded with filename", info.filename);
    console.log("Access it on s3 at", info.fileUrl);
   
  };

const uploadOptions = {
    server: "http://localhost:3000",
    accept: 'image/*',
    autoUpload: true
    };
  const s3Url = "https://mybucket.s3.sa-east-1.amazonaws.com";
  
  <DropzoneS3Uploader
      onFinish={handleFinishedUpload}
      s3Url={s3Url}
      maxSize={5000*5000}
      upload={uploadOptions}
 />

Then in the server.js

import reactS3 from "react-dropzone-s3-uploader/s3router.js";

app.use('/s3', (reactS3)({
  bucket: 'mybucket',                      
  region: 'us-east-1',                         
  headers: {'Access-Control-Allow-Origin': '*'}, 
  ACL: 'private',                           
}));

And in the .env file I have the access and secret access keys.

I'd appreciate any help

image orientation from iOS

Not sure if this is an issue with the uploader or not but when i take a picture in portrait mode from iOS and upload it with react-dropzone-s3-uploader it appears at a 90° angle when i go to view the image. Images taken in landscape mode are fine. Some preliminary research has me thinking it might have something to do with the exif info but I'm not sure if there is a way to set that info with the uploader or not. Pictures pulled from the camera roll seem to be fine. If anyone has seen this and has info great, otherwise you can close this issue. Thanks!

CORS Error on upload

I recently followed the guide and created this setup for my frontend react app as well as the express API on a separate project

Frontend
image

Backend
image

and i have a config.js with the secret key and access key to access my AWS. Once i put a .jpg image to drop zone i get this on server log

image

but i get this on fronted log

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403

Is there a way to find out what the actual issue is?

Invalid Response From Server

Hello,
can you help me, i have problem when i use react-dropzone-s3-uploader.
i upload my photo, and i got Message "Invalid Response From Server", why ?

const uploadOptions = {
            server: 'http://localhost:3000',
            signingUrlQueryParams: { uploadType: 'avatar' },
        }

const s3Url = 'https://hi.s3.amazonaws.com/' // i think Url like that( because i confuse to find url S3).

return (
<DropzoneS3Uploader
    onFinish={this.handleFinishedUpload}
    s3Url={s3Url}
    maxSize={1024 * 1024 * 5}
    upload={uploadOptions}
/>
)

Module not found: Can't resolve 'react-dropzone-s3-uploader'

I have installed all these libraries via:

npm install --save react-s3-uploader react-dropzone restuta-react-dropzone-s3-uploader && npm start

And I am still getting this error:

./src/components/MediaHome/index.js
Module not found: Can't resolve 'react-dropzone-s3-uploader' in '\src\components\MediaHome'

My code is


import React, { Component } from 'react';
import DropzoneS3Uploader from 'react-dropzone-s3-uploader'

class MediaHome extends Component {

  componentDidMount() {
    // TODO 
  }

  render() {

    return (
      <div>
        <h1>Media</h1>
      </div>
    );
  }
}


I even downloaded the folder as a ZIP and tried manually putting in node_modules.

My package.json is

    "react": "^16.3.0",
    "react-datetime": "^2.14.0",
    "react-dom": "^16.3.0",
    "react-dropzone": "^4.2.9",
    "react-router-dom": "^4.2.2",
    "react-s3": "^1.2.4",
    "react-s3-uploader": "^4.8.0",
    "react-scripts": "1.1.1",
    "restuta-react-dropzone-s3-uploader": "^0.20.4",

s3Url, uploadedFiles, and uploaderOptions causing warnings in browser

Getting these warnings in the Chrome console. React 16.2.0

Warning: React does not recognize the s3Url prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase s3url instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Warning: React does not recognize the uploadedFiles prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase uploadedfiles instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Warning: React does not recognize the uploaderOptions prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase uploaderoptions instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.