使用 asp.net 将文件保存到 azure 文件
saving files to azure file using asp.net
我正在尝试做的事情的目标是拍摄照片并使用 dropzone 上传它(哪个 drop zone 对于我的实现方式来说工作正常)并将其加载到 NTFS 文件系统。我将 "uploadpath" 存储到我的 SQL 服务器,以便以后可以更快地拉取图像。我 运行 遇到的问题是我不知道如何将图像加载到 Azure 文件系统中。另外从我收集的信息来看,blob 存储并不是我需要使用的,因为它基于一种不使用 ntfs 的 table 存储格式。
我一直在努力研究这个,但我不知道从哪里开始......我已经阅读了 MSDN 中的几篇文章以试图理解它,但似乎我一直发现的一切都与 BLOB 有关存储空间。
foreach (string filename in Request.Files)
{
HttpPostedFileBase file = Request.Files[filename];
fname = file.FileName;
if (file != null && file.ContentLength > 0)
{
var path = Path.Combine(Server.MapPath("~/uploadeimg"));
string pathstring = Path.Combine(path.ToString());
string filename1 = Guid.NewGuid() + Path.GetExtension(file.FileName);
bool isexist = Directory.Exists(pathstring);
if (!isexist)
{
Directory.CreateDirectory(pathstring);
}
uploadpath = string.Format("{0}\{1}", pathstring, filename1);
file.SaveAs(uploadpath);
至于文档,以下链接是我阅读和查看的内容。
File Uploading to Azure Storage by ASP.NET Webpages
https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files
https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files
https://docs.microsoft.com/en-us/azure/storage/blobs/storage-dotnet-how-to-use-blobs
感谢你们提供的任何帮助。我希望在这种类型的编程中获得更多经验,我刚刚决定尝试一下,看看我能用它做什么。
我也要注意。我可以将文件保存在我托管项目的区域中,我也可以通过这种方式检索它们。但我不确定这是否是处理此问题的正确方法。
在 Azure 上,通常将文件存储在 BLOB 中。我建议将您的照片存储在 BLOB 上,而不是将它们存储到 Azure Web App 中。
保存到 Azure BLOB 中的所有对象都有自己的 URL,您可以将其存储在 SQL 数据库中以供日后检索。
检查 https://docs.microsoft.com/en-us/azure/storage/common/storage-decide-blobs-files-disks?toc=%2fazure%2fstorage%2ffiles%2ftoc.json#comparison-files-and-blobs 以获得 Azure 文件和 BLOBS 之间的清晰比较。
对于使用本机文件系统 API 的遗留应用程序,您可以mount your Azure File share in Azure VM or on-premises as the network drive, then access your file share just as the local file system. You could leverage AzCopy and Azure Storage Explorer管理您的文件存储。
对于 Azure Web Apps,您无法装载 Azure 文件共享。默认情况下,Azure Web 应用程序内容存储在由 Azure 端管理的 Azure 存储中。您可以只利用主目录访问 (d:\home) 并将您的文件存储在 Azure Web 上。您可以关注 Azure Web App sandbox 关于文件系统 Restrictions/Considerations 部分的详细信息。
总而言之,我们建议您将文件存储到 Azure Blob 存储中。您可以使用 azure 存储客户端库与您的 blob 存储进行通信,您可以遵循详细信息 here。
我正在尝试做的事情的目标是拍摄照片并使用 dropzone 上传它(哪个 drop zone 对于我的实现方式来说工作正常)并将其加载到 NTFS 文件系统。我将 "uploadpath" 存储到我的 SQL 服务器,以便以后可以更快地拉取图像。我 运行 遇到的问题是我不知道如何将图像加载到 Azure 文件系统中。另外从我收集的信息来看,blob 存储并不是我需要使用的,因为它基于一种不使用 ntfs 的 table 存储格式。
我一直在努力研究这个,但我不知道从哪里开始......我已经阅读了 MSDN 中的几篇文章以试图理解它,但似乎我一直发现的一切都与 BLOB 有关存储空间。
foreach (string filename in Request.Files)
{
HttpPostedFileBase file = Request.Files[filename];
fname = file.FileName;
if (file != null && file.ContentLength > 0)
{
var path = Path.Combine(Server.MapPath("~/uploadeimg"));
string pathstring = Path.Combine(path.ToString());
string filename1 = Guid.NewGuid() + Path.GetExtension(file.FileName);
bool isexist = Directory.Exists(pathstring);
if (!isexist)
{
Directory.CreateDirectory(pathstring);
}
uploadpath = string.Format("{0}\{1}", pathstring, filename1);
file.SaveAs(uploadpath);
至于文档,以下链接是我阅读和查看的内容。
File Uploading to Azure Storage by ASP.NET Webpages https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files
https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files
https://docs.microsoft.com/en-us/azure/storage/blobs/storage-dotnet-how-to-use-blobs
感谢你们提供的任何帮助。我希望在这种类型的编程中获得更多经验,我刚刚决定尝试一下,看看我能用它做什么。
我也要注意。我可以将文件保存在我托管项目的区域中,我也可以通过这种方式检索它们。但我不确定这是否是处理此问题的正确方法。
在 Azure 上,通常将文件存储在 BLOB 中。我建议将您的照片存储在 BLOB 上,而不是将它们存储到 Azure Web App 中。
保存到 Azure BLOB 中的所有对象都有自己的 URL,您可以将其存储在 SQL 数据库中以供日后检索。
检查 https://docs.microsoft.com/en-us/azure/storage/common/storage-decide-blobs-files-disks?toc=%2fazure%2fstorage%2ffiles%2ftoc.json#comparison-files-and-blobs 以获得 Azure 文件和 BLOBS 之间的清晰比较。
对于使用本机文件系统 API 的遗留应用程序,您可以mount your Azure File share in Azure VM or on-premises as the network drive, then access your file share just as the local file system. You could leverage AzCopy and Azure Storage Explorer管理您的文件存储。
对于 Azure Web Apps,您无法装载 Azure 文件共享。默认情况下,Azure Web 应用程序内容存储在由 Azure 端管理的 Azure 存储中。您可以只利用主目录访问 (d:\home) 并将您的文件存储在 Azure Web 上。您可以关注 Azure Web App sandbox 关于文件系统 Restrictions/Considerations 部分的详细信息。
总而言之,我们建议您将文件存储到 Azure Blob 存储中。您可以使用 azure 存储客户端库与您的 blob 存储进行通信,您可以遵循详细信息 here。