Comments (9)
@AustinGomez I've submitted a pull request with the necessary changes: #155
From this, you can do something like the following:
constructor(props) {
super(props);
this.uploader = null;
this.handleUpload = this.handleUpload.bind(this);
}
handleUpload() {
this.uploader.uploadFile();
}
render() {
return (
<div>
<ReactS3Uploader
autoUpload={false}
ref={uploader => { this.uploader = uploader; }}
...
/>
<input type="button" value="Upload" onClick={this.handleUpload} />
</div>
)
}
from react-s3-uploader.
I'm currently playing with this and haven't yet had time to try it out but I have modified the following which I'm hoping for results.
propTypes: {
signingUrl: PropTypes.string,
getSignedUrl: PropTypes.func,
preprocess: PropTypes.func,
onProgress: PropTypes.func,
onFinish: PropTypes.func,
onError: PropTypes.func,
signingUrlMethod: PropTypes.string,
signingUrlHeaders: PropTypes.oneOfType([
PropTypes.object,
PropTypes.func
]),
signingUrlQueryParams: PropTypes.oneOfType([
PropTypes.object,
PropTypes.func
]),
signingUrlWithCredentials: PropTypes.bool,
uploadRequestHeaders: PropTypes.object,
contentDisposition: PropTypes.string,
server: PropTypes.string,
scrubFilename: PropTypes.func,
s3path: PropTypes.string,
inputRef: PropTypes.func,
autoUpload: PropTypes.bool
},
getDefaultProps: function() {
return {
preprocess: function(file, next) {
console.log('Pre-process: ' + file.name);
next(file);
},
onProgress: function(percent, message) {
console.log('Upload progress: ' + percent + '% ' + message);
},
onFinish: function(signResult) {
console.log("Upload finished: " + signResult.publicUrl)
},
onError: function(message) {
console.log("Upload error: " + message);
},
server: '',
signingUrlMethod: 'GET',
scrubFilename: function(filename) {
return filename.replace(/[^\w\d_\-\.]+/ig, '');
},
s3path: '',
autoUpload: true
};
},
and for getInputProps function...
getInputProps: function() {
// declare ref beforehand and filter out
// `inputRef` by `ReactS3Uploader.propTypes`
var additional = {
type: 'file',
ref: this.props.inputRef
};
if ( autoUpload ) {
additional.onChange = this.uploadFile;
}
Then presumably, using the below properties, you can prevent it from auto uploading and then use the ref to call the uploadFile
function.
<ReactS3Uploader
autoUpload={false}
ref={uploader => { this.uploader = uploader; }}
...
/>
This is what I'm trying... however I'm off to grab some sleep so I shall test this tomorrow.
from react-s3-uploader.
@LKozakewycz Thanks for this. Gladly awaiting your work ๐
from react-s3-uploader.
+1 for this
from react-s3-uploader.
I was surprised that this feature wasn't implemented since this is a very common use case. +1
from react-s3-uploader.
Didn't see that this issue had so many votes! Yeah, it is totally a use-case we should support. Scanning the code, it shouldn't be too hard to conditionally omit the listener on this line, then just call uploadFile via a reference to the component. Anyone want to take a stab at a PR?
from react-s3-uploader.
Very surprised you can't do this yet. +1
from react-s3-uploader.
I appreciate your input @AustinGomez and others. I don't currently use this library, and don't have a lot of spare time at the moment - I just merge PRs and try to make sure things aren't broken. If anyone would like to provide this functionality, I'll be happy to review and merge. I usually get new features merged and released within a few hours. Thanks!
from react-s3-uploader.
Released v.4.6.0
with autoUpload={false}
support.
from react-s3-uploader.
Related Issues (20)
- MultipartUpload support๏ผ HOT 1
- Method Not Allowed 405 PUT Error
- index.d.ts missing methods/props HOT 1
- ReactS3Uploader.propTypes is undefined when deployed on Heroku HOT 3
- Domentation for all the props
- iPhone camera video quality issue
- Console Warning: getDefaultProps is only used on classic React.createClass...
- Content-Type is blank when uploading HOT 3
- How to notify server of image upload? HOT 1
- Is the "accept" prop even being used? Where can we find a list of valid prop arguments? (Duplication of #220) HOT 2
- Return boolean or Promise on file upload
- Can't limit upload size HOT 1
- Getting CORS error on uploading file on AWS S3 HOT 3
- Unable to generate a valid signed upload URL for Digital Ocean spaces
- Type for signingUrlHeaders is wrong HOT 2
- findDOMNode is deprecated in StrictMode HOT 1
- Uncaught ReferenceError: process is not defined - Chrome browser Console error HOT 2
- Upload error 400 after onProgress reports all the way through 100% HOT 4
- Mime-types modules is not intended to be used with browser HOT 2
- Upload error: Could not contact request signing server
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-s3-uploader.