Skip to content

Commit

Permalink
harunhasdal#4 - implemented custom onLoadComplete handler for non-ch…
Browse files Browse the repository at this point in the history
…unked uploads
  • Loading branch information
donarus committed Feb 16, 2017
1 parent 3513dfd commit 668d818
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion demo/Demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Demo = () => (
<XHRUploader url={UPLOAD_URL} />
</article>
<article>
<p>By default, the component uses POST method for file transfer. The component accepts the
<p>By default, the component uses POST method for file transfer. The component accepts the
</p><pre>method</pre><p> property to specify different http method.</p>
<pre style={{fontSize: 10}}>
{`
Expand All @@ -29,6 +29,20 @@ const Demo = () => (
</pre>
<XHRUploader url={UPLOAD_URL} method="PUT" />
</article>
<article>
<p>To set up handler handling responses after upload (successful or not) use
</p><pre>onLoadComplete</pre><p> property.</p>
<p className="alert"><strong>Note:</strong> This property is supported with non-chunked uploads only.</p>
<pre style={{fontSize: 10}}>
{`
<XHRUploader
url='${UPLOAD_URL}'
onLoadComplete={(response) => console.log(response)}
/>
`}
</pre>
<XHRUploader url={UPLOAD_URL} onLoadComplete={response => console.log(response)} />
</article>
<article>
<p>You can enable automatic upload after drag and drop or file selection with </p>
<pre>auto</pre>
Expand Down
4 changes: 4 additions & 0 deletions demo/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,7 @@ a {
.menu__all-charts {
color: #fba600 !important;
}

.alert {
color: firebrick;
}
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class XHRUploader extends Component {
formData.append(this.props.fieldName, file, file.name);

xhr.onload = () => {
if (this.props.onLoadComplete) {
this.props.onLoadComplete(xhr.response);
}
progressCallback(100);
};

Expand Down Expand Up @@ -315,7 +318,8 @@ XHRUploader.propTypes = {
cancelIconClass: PropTypes.string,
completeIconClass: PropTypes.string,
uploadIconClass: PropTypes.string,
progressClass: PropTypes.string
progressClass: PropTypes.string,
onLoadComplete: PropTypes.func
};

XHRUploader.defaultProps = {
Expand Down

0 comments on commit 668d818

Please sign in to comment.