How to save base64 encoded videos in go?

blov · · 314 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m new to go and working with an app in which users can post videos through JSON posts. I&#39;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 &#34;video&#34; bytes.</p></pre>moboto22: <pre><p>Yeah but I don&#39;t know how to use that. Need a working example. </p></pre>SmokyQuarks: <pre><p>Well, it&#39;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 := &#34;whatever&#34; 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&#39;s what I was looking for!</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

314 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传