Golang file upload with progress indicator

xuanbao · · 694 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I need to upload and process some files, is there any library that already deals with this?</p> <p>I have to process some large csv&#39;s and would like to have an UI with something similar to:</p> <blockquote> <p>Uploading file 30% ~&gt; 90% ~&gt; 100%</p> <p>File uploaded</p> <p>Found 100.000 rows</p> <p>Processing row 10 of 100.000</p> <p>Error in line 11: line has invalid values in column xyz</p> </blockquote> <p>Also with the ability for the user to cancel the processing.</p> <p>Edit: This is for a web api.</p> <hr/>**评论:**<br/><br/>jerf: <pre><p>Is this command-line, web oriented, or GUI oriented? </p> <p>There are a number of <a href="https://godoc.org/?q=progress" rel="nofollow">console-based progress bars</a>. You&#39;d have to do some adapting based on the results but it would be feasible.</p> <p>If it&#39;s web, I don&#39;t see anything on godoc for that. Because of the incredible diversity of web tech stacks I wouldn&#39;t expect anything off the shelf.</p> <p>If it&#39;s GUI, well, which one?</p></pre>drink_with_me_to_day: <pre><p>Mostly as an API, I need some solution to a website file uploader.</p> <p>I found one that would upload to S3 and do some minifications, etc, but it&#39;s not what I need.</p></pre>jerf: <pre><p>Yeah... if this is going over the web it&#39;s not very easy to describe the possible solutions, because there are so many, and they are all pretty much equally bad so there isn&#39;t a clear way to navigate them for you in a reddit post.</p> <p>I can offer the following hints, though:</p> <ol> <li><p>Don&#39;t forget that Go&#39;s model of HTTP server is quite good, and in particular, it accurately reflects the fact that a web request can contain a stream in it. When you get the <code>*http.Request</code> sent to your handler, that&#39;s the point in the network transaction where you have received the header but you have not necessarily received the body. You can manipulate the io.Reader of the body in all kinds of useful ways.</p></li> <li><p>In general, streaming things back out to the client is a nightmare of different approaches and tradeoffs. In this case I&#39;d recommend a search for <a href="https://www.html5rocks.com/en/tutorials/eventsource/basics/" rel="nofollow">server sent events</a>, but many things work. Kinda unfortunate how many things work, actually.</p></li> </ol></pre>drink_with_me_to_day: <pre><p>Server sent events seems like a good fit, thanks.</p></pre>ahmetlutfu: <pre><p>I was also looking for web today. you should use dropzonejs. and look this tutorial.</p> <p><a href="https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991" rel="nofollow">https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991</a></p></pre>dabshores: <pre><p>As you write to io.Writer, simply count the bytes written. To cancel hit control c.</p></pre>jayposs: <pre><p>Are you needing a web page that allows the user to select a file on their device (or local fileserver) and initiate an upload with a Go backend process to write the file to a server ? </p> <p>If so, I have used JQuery on the client and Go on the server to implement what you&#39;re looking for. The Go piece is quite straight forward.</p></pre>seankhliao: <pre><p>So you want a go backend + web api?</p> <p>File upload progress is probably better handled in the front end by some JavaScript plugin</p> <p>Then just poll the api every X seconds to get the update/state/errors</p> <p>And cancel by sending a request that sets a flag that the processor checks every time it&#39;s about to process a row</p></pre>

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

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