Firebase Firestorage上载过程从0跳到100 [英] Firebase Firestorage Upload Process Jump from 0 to 100

查看:70
本文介绍了Firebase Firestorage上载过程从0跳到100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular和Firebase实现文件上传.当我上传图像时,我希望显示从0到100的平滑过渡.但是现在我正在使用firebase的内置函数,当进程启动时它显示0,然后突然跳到100.

I am implementing a file upload using Angular and Firebase. When I am uploading an image I want to show a smooth transition from 0 to 100. But right now I am using firebase's builtin function and when the process starts it is showing 0 then suddenly jumping to 100.

var uploadTask = storageRef.child('images/rivers.jpg').put(file);

uploadTask.on('state_changed', function(snapshot){
  // Observe state change events such as progress, pause, and resume
  // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded

  this.selectedImageUrl = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;  //this.selectedImageUrl is my custom variable which I wan to show smooth Animation
  console.log('Upload is ' + this.selectedImageUrl + '% done');


}, function(error) {
  // Handle unsuccessful uploads
}, function() {

  uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
    console.log('File available at', downloadURL);
  });
});

推荐答案

您观察到的行为无法更改.

The behavior you're observing can't be changed.

在内部,SDK使用大缓冲区发送文件内容,并且进度仅在发送整个缓冲区后才会更新.如果要发送一个小文件,则单个缓冲区很可能包含整个文件.您无法更改内部缓冲区的大小,因此您必须接受它今天的工作方式.

Internally, the SDK uses a large buffer to send the contents of the file, and the progress only updates after an entire buffer is sent. If you're sending a small file, it's very possible that a single buffer contains the entire file. There's nothing you can do to change the size of the internal buffers, so you'll have to accept the way that it works today.

这篇关于Firebase Firestorage上载过程从0跳到100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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