上传提取的进度指标? [英] Upload progress indicators for fetch?

查看:135
本文介绍了上传提取的进度指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找使用抓取实施上传进度指标的文档或示例。



这是迄今为止我发现的唯一参考资料,其中规定:


进度事件是一个高级功能,暂时无法到达提取。您可以通过查看 Content-Length 标题并使用传递流来监控收到的字节来创建您自己的。



这意味着您可以不同地以 Content-Length 显式处理响应。当然,即使 Content-Length 存在,也可能是谎言。使用流,您可以处理这些谎言,无论您想要什么。


如何编写传递流以监控字节 ?如果它有什么不同,我试图通过浏览器将图片上传到 Cloudinary



注意:我 Cloudinary JS库,因为它依赖于jQuery而我的应用程序没有。我只对使用原生javascript和Github的 fetch polyfill来完成此操作所需的流处理感兴趣。






https://fetch.spec.whatwg.org/#fetch-api

流正开始登陆网络平台( https://jakearchibald.com/2016/streams-ftw/ ),但它仍然是早期的日子。



很快你就可以提供一个流作为请求的主体,但是开放的问题是该流的消耗是否与上传的字节有关。



<特殊重定向可能会导致数据重新传输到新位置,但流不能重新启动。我们可以通过将主体转换为可以多次调用的回调来解决这个问题,但我们需要确保暴露重定向的数量不是安全漏洞,因为它是第一次在平台上JS可以检测到这一点。



有些人质疑是否将流消费链接到上传的字节是否有意义。



Long故事简介:这还不可能,但将来这将由流处理,或者传递到 fetch()的某种更高级别的回调。


I'm struggling to find documentation or examples of implementing an upload progress indicator using fetch.

This is the only reference I've found so far, which states:

Progress events are a high level feature that won't arrive in fetch for now. You can create your own by looking at the Content-Length header and using a pass-through stream to monitor the bytes received.

This means you can explicitly handle responses without a Content-Length differently. And of course, even if Content-Length is there it can be a lie. With streams you can handle these lies however you want.

How would I write "a pass-through stream to monitor the bytes" sent? If it makes any sort of difference, I'm trying to do this to power image uploads from the browser to Cloudinary.

NOTE: I am not interested in the Cloudinary JS library, as it depends on jQuery and my app does not. I'm only interested in the stream processing necessary to do this with native javascript and Github's fetch polyfill.


https://fetch.spec.whatwg.org/#fetch-api

解决方案

Streams are starting to land in the web platform (https://jakearchibald.com/2016/streams-ftw/) but it's still early days.

Soon you'll be able to provide a stream as the body of a request, but the open question is whether the consumption of that stream relates to bytes uploaded.

Particular redirects can result in data being retransmitted to the new location, but streams cannot "restart". We can fix this by turning the body into a callback which can be called multiple times, but we need to be sure that exposing the number of redirects isn't a security leak, since it'd be the first time on the platform JS could detect that.

Some are questioning whether it even makes sense to link stream consumption to bytes uploaded.

Long story short: this isn't possible yet, but in future this will be handled either by streams, or some kind of higher-level callback passed into fetch().

这篇关于上传提取的进度指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆