我一直在到处寻找有关制作组件的帮助,以帮助管理从React中上传文件到我设置的端点。
我尝试过很多方法,包括集成filedropjs。我决定不使用它,因为我无法控制它使用new FileDrop('zone', options);
在DOM中设置的元素
这就是我到目前为止所知道的:
module.exports = React.createClass({
displayName: "Upload",
handleChange: function(e){
formData = this.refs.uploadForm.getDOMNode();
jQuery.ajax({
url: 'http://example.com',
type : 'POST',
xhr: function(){
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){
myXhr.upload.addEventListener('progress',progressHandlingFunction, false);
}
return myXhr;
},
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data){
alert(data);
}
});
},
render: function(){
return (
<form ref="uploadForm" className="uploader" encType="multipart/form-data" onChange={this.handleChange}>
<input ref="file" type="file" name="file" className="upload-file"/>
</form>
);
}
});
},
render: function(){
console.log(this.props.content);
if(this.props.content != ""){
return (
<img src={this.props.content} />
);
} else {
return (
<form className="uploader" encType="multipart/form-data" onChange={this.handleChange}>
<input ref="file" type="file" name="file" className="upload-file"/>
</form>
);
}
}
});
如果有人能给我指出正确的方向,我会给你一些虚拟的拥抱。我已经在这方面做了相当广泛的工作。我觉得我已经很接近了,但还不够。
谢谢!
https://stackoverflow.com/questions/28750489
复制相似问题