使用redux形式加载图像
我有 react.js Redux形式,工作并将数据发送回我的数据 API, 但是,我还需要允许发件人携带窗体,理想地与预览。 我争吵了一点,得了 dropzone.js, 但似乎我不能让我的表格真的 POST 返回图像数据。
多变的
真的回报 POSTed 返回K. API, 什么是精彩的,但它包含以下内容:
有人可以告诉我如何在这个变量中获得实际二进制数据,请?
这里提供的完整代码
https://github.com/rushughes/d ... ex.js
render // {
const FILE_FIELD_NAME = 'files';
const renderDropzoneInput = /field/ => {
const files = field.input.value;
return /
<div>
<dropzone =="" e="" filestoupload,="" name="{field.name}" ondrop="{/"> field.input.onChange/filesToUpload/}
>
<div>Try dropping some files here, or click to select files to upload.</div>
</dropzone>
{field.meta.touched &&
field.meta.error &&
<span classname="error">{field.meta.error}</span>}
{files && Array.isArray/files/ && /
<ul>
{ files.map//file, i/ => <li key="{i}">{file.name}<img src="{file.preview}/"/></li>/ }
</ul>
/}
</div>
/;
}
return /
<form onsubmit="{this.props.handleSubmit/this.onSubmit/}">
<div classname="form-group">
<field component="{renderDropzoneInput}" name="files"></field>
</div>
<button classname="btn btn-default" type="submit">Submit</button>
</form>
/;
}
多变的
files
真的回报 POSTed 返回K. API, 什么是精彩的,但它包含以下内容:
[preview=blob:[url=http://localhost:3000/bed3762e-a4de-4d19-8039-97cebaaca5c1]http://localhost:3000/bed3762e ... ca5c1[/url]]
有人可以告诉我如何在这个变量中获得实际二进制数据,请?
这里提供的完整代码
https://github.com/rushughes/d ... ex.js
没有找到相关结果
已邀请:
3 个回复
石油百科
赞同来自:
然后你发送 Base64 或二进制字符串到服务器。
我的示例代码:
如果要发送二进制字符串 base64, 修正案
在
这行:
可以在之前简化
诸葛浮云
赞同来自:
: /如何处理您的图像数据 API/
添加您的值 redux-form 到
复制 FormData.
发送请求
从客户到您的图书馆 API 与图书馆
https://github.com/axios/axios
或者
:
获取此查询
在你的 API, 继续它
https://github.com/expressjs/multer
, 然后写入文件
或者
通过以下方式:
/选修的/ 与文件一起使用文件 API
http://expressjs.com/en/starter/static-files.html
快网
赞同来自:
http://reactdropzone.azurewebsites.net/example/
/
这里可以找到哪些代码:
https://react.rocks/example/React-Dropzone
此外,这些决定还将帮助您以某种方式摆脱问题:
https://github.com/react-dropzone/react-dropzone
https://medium.com/technoetics ... 68f6b
http://blog.mauriziobonani.com ... tion/
/
https://css-tricks.com/image-u ... eact/
/
https://www.reddit.com/r/react ... eact/
/