Azure Blob文件URL [英] Azure Blob Files URL

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

问题描述

您好,我找到了本指南:https://docs.microsoft.com/zh-CN/azure/storage/blobs/storage-quickstart-blobs-javascript-client-libraries

按照所有步骤操作后,我已成功为我的网站创建了一个上传器.

我想像使用AWS存储帐户一样使用它,在这里我可以通过javascript上传文件,并在上传后从服务器获取URL/md5.

我正在使用它:

 document.getElementById('上传按钮').addEventListener('click',()=> {

    const file = document.getElementById('fileinput').files [0];

    blobService.createBlockBlobFromBrowserFile('mycontainer',
                                                文件名,
                                                文件,
                                                (错误,结果)=> {
                                                    如果(错误){
                                                        //处理Blob错误
                                                    } 别的 {
                                                        console.log('上传成功');
                                                    }
                                                });

}); 


正如我所说的那样,我可以在我的Azure帐户>中看到文件. Blob容器.

我有2个问题:

1-上传后如何获取链接.该代码不允许访问blob,例如:

console.log(blob);

我尝试过:

blobService.createBlockBlobFromBrowserFile('uploadbubble', 文件名, 文件, (错误,结果)=> { 如果(错误){ } 别的 { console.log('上传成功'); blobService.listBlobsSegmented('uploadbubble',null,(错误,结果)=> { 如果(错误){ //处理列表斑点错误 } 别的 { results.entries.forEach(blob => { console.log(blob); }); } });

但是它列出了我所有的Blob,而不是最后一个上传的Blob.甚至在检查了Blob之后,我只看到了md5,而不是CDN  URL.

2-为什么当我上传两次相同的文件而不是创建一个新文件时,它取代了现有文件?

致谢.

     我该怎么办上传后获取链接.

参考:  http://azure.github.io/azure-storage-node/BlobService.html#getUrl

  http: //gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/

,使用该标头可以防止覆盖Blob.您可以阅读有关条件标题的更多信息 此处: 由于您不希望覆盖Blob,因此需要指定 如果不适用-Match 条件标头并将其值设置为 *

链接 正在更新现有块blob会覆盖blob上的所有现有元数据. Put Blob;不支持部分更新这 现有Blob的内容将被新Blob的内容覆盖.

免责声明:此回复包含对第三方万维网的引用地点. Microsoft为方便您而提供此信息.微软 不控制这些站点,也没有测试在这些站点上找到的任何软件或信息;因此,Microsoft无法对在此找到的任何软件或信息的质量,安全性或适用性做出任何陈述.有内在的 使用Internet上发现的任何软件都存在危险,Microsoft提醒您在从Internet上检索任何软件之前,请务必完全了解该风险.

-------------- -------------------------------------------------- ----------------------------------

如果此答案有帮助,点击"标记为答案"或 投票.要提供有关您的论坛体验的其他反馈,请单击 在这里

document.getElementById('upload-button').addEventListener('click', () => { const file = document.getElementById('fileinput').files[0]; blobService.createBlockBlobFromBrowserFile('mycontainer', file.name, file, (error, result) => { if(error) { // Handle blob error } else { console.log('Upload is successful'); } }); });


Which as I said works perfect, I see the files in my Azure account > Blob container.

I have 2 questions:

1- How I can get the link after uploading. That code doesn't permit to access to blob like:

console.log(blob);

I tried this:

blobService.createBlockBlobFromBrowserFile('uploadbubble', 
                            	file.name, 
                            	file, 
                            (error, result) => {
                               if(error) {
                                 
                               } else {
                               console.log('Upload is successful');
                                  blobService.listBlobsSegmented('uploadbubble', null, (error, results) => {
        if (error) {
            // Handle list blobs error
        } else {
            results.entries.forEach(blob => {
                console.log(blob);
            });
        }
    });

But it lists me all the blobs instead of the last one uploaded. And even after inspecting the blob, I only see the md5, not the CDN URL.

2- Why when I upload two times the same file instead of creating a new file it replaces the existing one?

Regards.

解决方案

1-     How I can get the link after uploading.

You might want to call blobService.getUrl(containerName, blobName)

Refer: http://azure.github.io/azure-storage-node/BlobService.html#getUrl

 http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/

2- Why when I upload two times the same file instead of creating a new file it replaces the existing one?

If a blob exists in blob storage and if you upload another file with the same name as that of the blob, old blob contents will automatically be replaced with the contents of new file. It’s a default nature of blobs.

Windows Azure Blob Storage supports conditional headers using which you can prevent overwriting of blobs. You can read more about conditional headers here: http://msdn.microsoft.com/en-us/library/windowsazure/dd179371.aspx.

Since you want that a blob should not be overwritten, you would need to specify If-None-Match conditional header and set its value to *

See the link which is updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with Put Blob; the content of the existing blob is overwritten with the content of the new blob.

Disclaimer: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

--------------------------------------------------------------------------------------------------

If this answer was helpful, click "Mark as Answer" or Up-Vote. To provide additional feedback on your forum experience, click here




这篇关于Azure Blob文件URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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