我正在尝试在我的应用程序上实现 react-dropzone 但我无法发布并且总是得到Internal Server Error和 error: TypeError: argument should be a bytes-like object or ASCII string, not 'list' in case data帖子必须使用转换 base64
这是我的 onDrop 功能
onDrop(uploadData) {
this.setState({
uploadData,
});
}
onDropHandler(uploadData) {
var uploadData = uploadData[0];
const reader = new FileReader();
reader.readAsDataURL(uploadData);
reader.onload = event => {
this.setState({
uploadData: this.state.uploadData([{ base64: event.target.result }]),
});
};
reader.readAsDataURL(uploadData);
}
这是我的渲染方法:
<div className="dropzone">
<Dropzone
onDrop={this.onDrop.bind(this)}
accept="image/jpeg, image/png, image/jpg"
onDrop={uploadData => {
this.setState({ uploadData });
}}
maxSize={200000}
multiple={false}
>
<p>Maksimal 2 MB (JPG/PNG)</p>
</Dropzone>
{this.state.uploadData.map(f => (
<span key={f.name}>
{f.name} - {f.size} bytes
</span>
))}
</div>