简体   繁体   English

使用 blob 的 url 和 node.js 中的 sas 令牌下载 blob

[英]Download blob using url of the blob and sas token in node.js

I am very new to java script.我对 java 脚本非常陌生。 I want to download a blob file from the azure blob storage.我想从 azure blob 存储下载一个 blob 文件。 I have the sas token and complete url to the individual block blob The url looks like this: https://xxxxxxxxxx.blob.core.windows.net/ABC/ABC/20216063/cvf.gbl I have the sas token and complete url to the individual block blob The url looks like this: https://xxxxxxxxxx.blob.core.windows.net/ABC/ABC/20216063/cvf.gbl

In online i have come across download methods which require container name and blob name.在网上我遇到了需要容器名称和 blob 名称的下载方法。 I dont know the container name and blob name.我不知道容器名称和 blob 名称。 i have the url to the individual blob file.我有 url 到单个 blob 文件。

How to download the blob using only sas token and the blob url using java script?如何仅使用 sas 令牌和使用 java 脚本的 Blob url 下载 blob?

You could create an HTTP GET request and pipe its response into a writable file stream.您可以将 HTTP GET 请求和 pipe 其响应创建到可写文件 stream 中。 With the below code you could download the file if you don't the blob name.如果您没有 blob 名称,则可以使用以下代码下载文件。

    const sasurl="your sas url";
    const https = require('https');
    const url = require('url');;
    const path = require('path');
    const fs = require('fs');
    const filename=url.parse(sasurl).pathname.split('/').pop();
    const file = fs.createWriteStream(filename);
    const request = https.get(sasurl, function(response) {
    response.pipe(file);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM