小编Jak*_*222的帖子

HttpResponseMessage 重定向到私有 Azure Blob 存储

使用 asp.net 开发 API

是否可以将用户重定向到私有 azure blob 存储?我可以使用 SAS 密钥或 azure blob SDK 执行此操作吗?

例如我想做这样的事情:

var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;
Run Code Online (Sandbox Code Playgroud)

是否可以通过将密钥放入 URL 来访问私有 blob?显然我不想放主钥匙。

c# asp.net azure azure-blob-storage

6
推荐指数
1
解决办法
1698
查看次数

CloudBlockBlob.DownloadToStream与DownloadRangeToStream

尝试使用ASP.NET azure SDK从blob存储中下载图像.

我在另一篇文章中读到,DownloadToStream确实将blob破碎成小块并且并行下载它们以提高性能.我相信这就是DownloadRangeToStream的用途.

我无法找到任何关于DownloadToStream的文档或代码确认,并且持怀疑态度,因为它具有与blob url直接下载相同的运行时(每次下载.5-3s).这是我的下载方法的代码,给出了相同的性能.

使用CloudBlockBlob.DownloadToStream:

private Bitmap DownloadFromBlob(String set) {

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString"));

    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    CloudBlobContainer container = blobClient.GetContainerReference("templates");

    CloudBlockBlob blockBlob = container.GetBlockBlobReference(set + ".png");

    using (var memoryStream = new MemoryStream()) {
        blockBlob.DownloadToStream(memoryStream);

        return (memoryStream == null) ? null : (Bitmap)Image.FromStream(memoryStream);
    }
}
Run Code Online (Sandbox Code Playgroud)

使用Image.FromStream:

private Bitmap DownloadImageFromUrl(string url) {
    try {
        using (WebClient client = new WebClient()) {
            byte[] data = client.DownloadData(url);
            using (MemoryStream mem = (data == null) ? null : new MemoryStream(data)) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net azure azure-storage-blobs azure-sdk-.net

5
推荐指数
1
解决办法
5885
查看次数

Azure Blob vs文件vs磁盘存储

快速提问。我一直在阅读大量有关azure blob /文件/磁盘存储选项的信息,并且我对存储的要求如此简单,因此我对最佳选择感到困惑。我正在阅读的大多数信息完全笼罩着我。

我希望有人可以将视野缩小到更合理大小的一组优点/缺点。我的情况如下:

我正在建立一个进行图像处理的API。简而言之,用户请求获取具有特定文本的特定图像以打印在顶部,我的API对其进行处理并将其吐出。目前,我正在Azure模拟器上运行,因此图像文件(大约3演出的PNG)是从本地路径中提取的。我很快将部署到实时的Azure服务器上,因此我想将这些图像文件存储在某个位置(而不将它们放置在实际的应用程序文件中)。

到目前为止,我的理解是磁盘和文件选项将使我可以使代码保持相对不变,同时仍使用常规文件I / O来加载映像路径。磁盘将仅允许对运行此API的计算机进行数据访问,这很好,但是我不知道使用磁盘是否有任何好处,这会施加此限制。Blob存储将要求我更改此设置,但是没有太多代码,并且我不认为这会太困难。

每个不同选择的细节太多,以至于我难以做出决定:就我的情况而言,这三个之间是否有明确的选择?它归结为更容易的事情吗?性能和成本是重中之重,那么在这些方面的利弊是什么?这确实需要能够缩放到更多图像,但只能缩放到一定程度。我可以看到,在接下来的几年中,它的数量将从3个演出增加到10个演出,但不会从3个演出增加到1000个演出。

.net azure azure-storage azure-storage-blobs azure-storage-files

3
推荐指数
1
解决办法
3077
查看次数

React.useEffect:尽管来自 ESLint 的警告(react-hooks/exhaustive-deps),组件仍使用依赖项数组中的 window.location.pathname 重新渲染

我有一个左侧菜单,其中包含需要根据当前 URL 路径选择/取消选择的子选项。在寻找解决方案的过程中,我发现以下代码给出了 ESLint 错误,如下所示:

useEffect(() => {
    if (window.location.pathname === "/events/list") {
      setManageEventsOpen(true);
      setSelectedListItem(LIST_SELECTED);
    }
    if (window.location.pathname === "/events/map") {
      setManageEventsOpen(true);
      setSelectedListItem(MAP_SELECTED);
    }
    if (window.location.pathname === "/events/calendar") {
      setManageEventsOpen(true);
      setSelectedListItem(CALENDAR_SELECTED);
    }
  }, [window.location.pathname]);

React Hook useEffect has an unnecessary dependency: 'window.location.pathname'. 
Either exclude it or remove the dependency array. 
Outer scope values like 'window.location.pathname' aren't valid 
dependencies because mutating them doesn't re-render 
the component.eslint(react-hooks/exhaustive-deps)
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此代码时,我注意到当路径更改时组件会重新渲染。我认为这只是因为在手动更改 URL 并刷新页面时整个应用程序正在重新加载,但即使从另一个组件使用 History.push('/events/list') 也会导致重新渲染。

我想知道,这个警告不正确吗?有人看到不同的结果吗?

注意:我在我的应用程序中对此有更好的解决方案,但我仍然对警告感到好奇。

reactjs eslint react-router

2
推荐指数
1
解决办法
5278
查看次数