简体   繁体   English

文件上传到Windows Azure Blob

[英]Files upload to Windows Azure Blob

I am new in Web Development but i am confusing my concepts So I have 2 question 我是Web开发的新手,但我的概念令人困惑,所以我有2个问题

1->What is the difference between my PDF link URL " https://hrbcdev.blob.core.windows.net/uploads/UserForms/reportlayout-130334646861135641.pdf " and any normal PDF Google link " http://www.syncfusion.com/Content/downloads/ebook/Knockoutjs_Succinctly.pdf " because my link downloads the PDF while the other one opens in the Browser. 1->我的PDF链接URL“ https://hrbcdev.blob.core.windows.net/uploads/UserForms/reportlayout-130334646861135135.pdf ”和任何常规的PDF Google链接“ http:// www。之间有什么区别 之所以要使用syncfusion.com/Content/downloads/ebook/Knockoutjs_Succinctly.pdf,是因为我的链接下载了PDF,而另一个链接在浏览器中打开。

2-> I am using Windows Azure Blob to upload PDF files to server but when i click on these files it will automatically start download. 2->我正在使用Windows Azure Blob将PDF文件上传到服务器,但是当我单击这些文件时,它将自动开始下载。 But i want to open in a new tab instead of download it.... Is there any property during document uploading which tells the server about the file whether it is downloadable or not. 但是我想在一个新选项卡中打开而不是下载它。...在文件上载期间是否有任何属性可以告诉服务器有关文件的信息,该文件是否可下载。 Here is my Code: 这是我的代码:

[HttpPost]
    public virtual ActionResult UploadFile(string kind, int? entityId = null) // optionally receive values specified with Html helper
    {
        // here we can send in some extra info to be included with the delete url 
        var statuses = new List<ViewDataUploadFileResult>();
        var thumbnailKind = AppConfig.KnownKind(kind);
        var uploadLocation = AppConfig.UploadLocation(thumbnailKind);
        for (var i = 0; i < Request.Files.Count; i++)
        {
            var storage = new AzureFileStorage();

            var st = storage.StoreFile(x =>
                            {
                                x.File = Request.Files[i];
                                x.Kind = thumbnailKind;
                                //note how we are adding an additional value to be posted with delete request
                                //and giving it the same value posted with upload
                                x.DeleteUrl = Url.Action(MVC.FileUploader.DeleteFile(entityId));
                                x.StorageDirectory = uploadLocation.Path;
                                x.UrlPrefix = uploadLocation.Url;
                            });


            statuses.Add(st);
        }
        var json = new { files = statuses };
        return Request.Headers["ACCEPT"].Contains("application/json")
            ? Json(json)
            : (ActionResult)Content(json.ToJson());
    }

1->What is the difference between my PDF link URL " https://hrbcdev.blob.core.windows.net/uploads/UserForms/reportlayout-130334646861135641.pdf " and any normal PDF Google link " http://www.syncfusion.com/Content/downloads/ebook/Knockoutjs_Succinctly.pdf " because my link downloads the PDF while the other one opens in the Browser. 1->我的PDF链接URL“ https://hrbcdev.blob.core.windows.net/uploads/UserForms/reportlayout-130334646861135135.pdf ”和任何常规的PDF Google链接“ http:// www。之间有什么区别 之所以要使用syncfusion.com/Content/downloads/ebook/Knockoutjs_Succinctly.pdf,是因为我的链接下载了PDF,而另一个链接在浏览器中打开。

Please check the content-type property of the blob. 请检查Blob的content-type属性。 In all likelihood, it is coming back as application/octet-stream (which is the default content type in blob storage). 它很可能以application/octet-stream (这是Blob存储中的默认内容类型)的形式返回。 Because the browser (especially Chrome/Firefox) rely on this property to decide whether to show the content inline in the browser or download the file and this is not set as application/pdf , browser decides to download the file. 因为浏览器(尤其是Chrome / Firefox)依靠此属性来决定是在浏览器中内联显示内容还是下载文件,并且未将其设置为application/pdf ,所以浏览器决定下载文件。 You can change the content-type property of the blob programmatically even after the blob is uploaded. 即使已上传Blob,也可以通过编程方式更改Blob的content-type属性。

2-> I am using Windows Azure Blob to upload PDF files to server but when i click on these files it will automatically start download. 2->我正在使用Windows Azure Blob将PDF文件上传到服务器,但是当我单击这些文件时,它将自动开始下载。 But i want to open in a new tab instead of download it.... Is there any property during document uploading which tells the server about the file whether it is downloadable or not. 但是我想在一个新选项卡中打开而不是下载它。...在文件上载期间是否有任何属性可以告诉服务器有关文件的信息,该文件是否可下载。

Assuming by downloadable you mean whether user is always prompted to download the blob instead of displaying it inline, recently Windows Azure Storage announced some changes and one of the things they announced is the ability to set Content-Disposition property on a blob. 假设可downloadable ,是指是否总是提示用户下载Blob而不是内联显示它,最近Windows Azure存储宣布了一些更改,他们宣布的一件事是可以在Blob上设置Content-Disposition属性。 For a blob which you wish to get downloaded all the time, please set its Content-Disposition property to attachment; filename=<blob file name> 对于您希望一直下载的Blob,请将其Content-Disposition属性设置为attachment; filename=<blob file name> attachment; filename=<blob file name> and then user will always be prompted to download the blob. attachment; filename=<blob file name> ,然后将始终提示用户下载blob。 You can read more about the new changes here: http://blogs.msdn.com/b/windowsazurestorage/archive/2013/11/27/windows-azure-storage-release-introducing-cors-json-minute-metrics-and-more.aspx . 您可以在此处了解有关新更改的更多信息: http : //blogs.msdn.com/b/windowsazurestorage/archive/2013/11/27/windows-azure-storage-release-introducing-cors-json-minute-metrics-和更多.aspx

However if by downloadable you mean securing the blob, please see the answer by @ramiramilu to your 2nd question. 但是,如果通过downloadable获取安全性,请参阅@ramiramilu对第二个问题的回答。

For Question (1) - When you set Content-Dispostion header to inline, browser tries to open the file in itself. 对于问题(1)-当您将Content-Dispostion标头设置为内联时,浏览器会尝试自行打开文件。 If it was set to attachment, then browser will try to open popup for downloading the file. 如果将其设置为附件,则浏览器将尝试打开弹出窗口以下载文件。 Either in both the cases, file will be downloaded to client browser. 在这两种情况下,文件都将下载到客户端浏览器。 So this behaviour purely depends on the type of browsers. 因此,此行为纯粹取决于浏览器的类型。

[EDIT] I agree with Gaurav for Question (1), but there is a possibility for blob having Content-Type as application/pdf and Content-Disposition to be attachment. [编辑]我同意问题(1)的高拉夫(Gaurav),但是有可能将Content-Type作为application / pdf和Content-Disposition作为附件。

For Question (2) - You can restrict access for the file by modifying the container access modifiers like Private, public container, public blob. 对于问题(2)-您可以通过修改容器访问修饰符(例如“私有”,“公共容器”,“公共blob”)来限制文件访问。 You can set it to private so that the contents of that container will be accessible directly. 您可以将其设置为私有,以便可以直接访问该容器的内容。 As per Microsoft - " By default, the container is private and can be accessed only by the account owner. To allow public read access to the blobs in the container, but not the container properties and metadata, use the "Public Blob" option. To allow full public read access for the container and blobs, use the "Public Container" option. " 按照Microsoft的规定-“ 默认情况下,容器是私有的,只能由帐户所有者访问。要允许对容器中的Blob(而不是容器属性和元数据)进行公开读取访问,请使用” Public Blob“选项。要允许对容器和Blob进行完全公共的读取访问,请使用“公共容器”选项。

You can also protect your blobs using SAS - http://www.dotnetcurry.com/showarticle.aspx?ID=901 您还可以使用SAS保护您的斑点-http: //www.dotnetcurry.com/showarticle.aspx? ID=901

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

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