Blob downloadToFile()不下载大文件Node.js [英] Blob downloadToFile() not downloading large files Nodejs

查看:86
本文介绍了Blob downloadToFile()不下载大文件Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中实现了** azure blob/storage **.它在较小的文件上工作正常,但是当我尝试下载40 MB以上的文件时.它不会从blob.downlaodToFile()返回这是我的代码. Api通话

I have implemented ** azure blob/storage** in my project. And it works fine on smaller files but when I try to download a file more than 40 MB. it does not return from blob.downlaodToFile() Here is my code. Api call

exports.downloadSingle = function(req,res){
  downloadService.downloadSingleFile(req.params.id).then(function (result) {
    res.send(result);
  })
}

下载服务

    var filesLocalLinks = [];
    const request = require('request-promise');
    const fs = require('fs');
    var download = require('download-file')
    let promise = new Promise((resolve, reject) => {
      filemodel.findOne({_id: id,cancelled: false}).exec(function(error,result){
        if(error){
          resolve(error);
        }else{
          
              blobDownload.downloadFile(result.blobName,result.containerName).then(function(blobResponse){
                var filename = path.resolve(__dirname+'/../services/uploads/'+result.fileName);
                   filename = filename.replace('/myProject','');
                   filename = process.env.BASE_URL+'/myProject/services'+filename.split('/services')[1];
                   resolve({file: filename, filename: result.originalname})
              }).catch(function(error){
                reject(error);
              })
        }
      })

    })
    let result =await promise;
    return {file: result.file,filename: result.filename };
  }

Blob服务

    let promise = new Promise(async (resolve, reject) => {
    const account = process.env.BLOB_ACCOUNT;
    const accountKey = process.env.BLOB_ACCOUNT_KEY;
    const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
    const blobServiceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      sharedKeyCredential
    );
    const containerClient = blobServiceClient.getContainerClient(containerName);
    const blockBlobClient = containerClient.getBlockBlobClient(blobName);
    const blobClient = containerClient.getBlobClient(blobName);
    var blobResponse = await blobClient.downloadToFile(blobName);
    resolve(blobResponse)
    })
    let result =await promise;
    return result;

  }

在Blob服务中,此行花费太多时间,导致页面无法响应页面. var blobResponse = await blobClient.downloadToFile(blobName); 谁能帮我

推荐答案

基本上,代码流是,首先将文件下载到我们的服务器目录中,然后用户可以下载它.我发现代码可以正常工作,但是问题出在我们服务器的内存上,随着我们增加内存,问题得以解决.但是花了我两天的时间

Basically the flow of code is, first it download the file to our server directory and then the user can download it. I figured it out that the code was working fine, but the issue was of the memory of our server, as we increased the memory, the issue is resolved. But it took my 2 days to figure it out

这篇关于Blob downloadToFile()不下载大文件Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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