本文介绍了OVH对象存储,当我尝试上传大文件(超过100 Ko)时,什么也没有发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用OVH对象存储上传文件.但是根据文件繁重,我有三种不同的行为.

I try to upload files with OVH object storage.But I have three different behavior according to the heavy file.

  • 具有小于100Ko的重量文件,一切正常

  • With a weight file which less than 100Ko, everything is ok

对于重量超过100Ko的重量文件,出现以下错误:Error: write after end,但是该文件已上传到ovh对象存储中

With a weight file which more than 100Ko, I have this error: Error: write after end, but the file is uploaded on ovh object storage

对于重量超过250Ko的重量文件,什么也不会发生,并且不会上传该文件.fs ReadStream已打开,但是通过管道传输(与读取流一起)的写入流未完成.

With a weight file which more than 250Ko, nothing happens, and the file is not uploaded.The fs ReadStream is open, but the write stream piped (with the read stream) not finish.

这是我的代码:

  var client = require('pkgcloud').storage.createClient({
    provider: 'openstack',
    username: myusername,
    password: mypassword,
    region: 'GRA',
    authUrl: 'https://auth.cloud.ovh.net/'
  });

  const fsReadStream = fs.createReadStream(path.resolve(__dirname, fileLocation))

  let writeStream = client.upload({
    container: myOvhStorageContainer,
    remote: 'fileName.jpg',
  });

  writeStream.on('error', function (err) {

    console.log(err)
  });

  writeStream.on('success', async function (file) {
    console.log(file)
  });

  fsReadStream.on('open', function () {
    console.log('open!!')

    fsReadStream.pipe(writeStream);
  });

推荐答案

问题来自 pkgcloud 中的错误,该错误在于它如何为OpenStack Storage流文件.

The problem comes from a bug in pkgcloud in how it streams files for OpenStack Storage.

https://github.com中公开了解决方案,并提出了修复程序. /pkgcloud/pkgcloud/pull/673

pkgcloud 的分支包含建议的修补程序,可以在等待正式接受该修补程序的同时使用它们:

There are forks of pkgcloud that include the proposed fix, and they can be used while waiting for the fix to be officially accepted:

  • https://github.com/madarche/pkgcloud/
  • https://github.com/StartupFlow/pkgcloud/tree/fix_write_after_end

要在项目/应用程序中使用这样的存储库,请编辑package.json来修改dependencies,如下所示:

To use such a repository in your project/application, edit your package.json to modify the dependencies like this:

"dependencies": {
    …
    "pkgcloud": "https://github.com/madarche/pkgcloud.git#fe2701eb6eb984e3d067d5df7610ca0751528dbd",
    …
  },

您还可以简单地创建自己的pkgclould分支,因此您不必信任随机的Git存储库.

You can also simply create your own fork of pkgclould, so you don't have to trust a random Git repository.

这篇关于OVH对象存储,当我尝试上传大文件(超过100 Ko)时,什么也没有发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 01:47