<p>I'm new to go and working with an app in which users can post videos through JSON posts. I'm wondering how to save these videos? What decoders should I use? I could not find any tutorial about that. So a complete code snippet would be much appreciated. </p>
<hr/>**评论:**<br/><br/>raff99: <pre><p>You can use a base64 Decoder (<a href="https://golang.org/pkg/encoding/base64/#NewDecoder" rel="nofollow">https://golang.org/pkg/encoding/base64/#NewDecoder</a>) and feed it with the json "video" bytes.</p></pre>moboto22: <pre><p>Yeah but I don't know how to use that. Need a working example. </p></pre>SmokyQuarks: <pre><p>Well, it's not that hard really. Not going into a lot of details, but assuming you have a string that contains the base64 encoded video, you can create a strings.Reader from it, then create a base64 decoder from that, something like this:</p>
<pre><code>b64data := "whatever"
reader := strings.NewReader(b64data)
decoder := base64.NewDecoder(base64.StdEncoding, reader)
decodedData := ioutil.ReadAll(decoder)
</code></pre>
<p>decodedData will be a byte[] containing all your data.</p></pre>moboto22: <pre><p>Thanks, that's what I was looking for!</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传