如何在Azure上存储PDF文件

7
我在Azure上运行一个带有MySql数据库的Linux上的WordPress应用程序。
我需要能够上传PDF文件到Azure,然后在网站上放置一个链接,使用户可以单击该链接并查看PDF文件。
更具体地说,文档是在本地创建的每月发票,然后上传到Azure。用户将登录,然后看到一个链接,允许他查看发票。
我不知道的是文档应该如何存储。它应该存储在MySql数据库中吗?还是存储在某种可以链接的存储中?当然,它需要是安全的。
3个回答

2

Greg,Azure中的Blob存储是您最好的选择,以下是它的功能:

1 -Serving images or documents directly to a browser
2 -Storing files for distributed access
3- Streaming video and audio
4- Storing data for backup and restore, disaster recovery, and archiving
5- Storing data for analysis by an on-premises or Azure-hosted service

在 Azure Blobs 中存储的任何文件都可以通过链接访问,例如: https://storagesample.blob.core.windows.net/mycontainer/blob1.txt 或使用别名,如 http://files.mycompany.com/somecontainer/bolbs.txt 完整详情请参见:https://learn.microsoft.com/en-us/azure/storage/blobs/storage-dotnet-how-to-use-blobs

1
你可以使用Azure Blob存储来上传/存储PDF文档。每个存储的文档都有一个链接,可以在你的网站中显示。此外,你还可以保护这些资源,并使用SAS、共享密钥身份验证机制来访问这些资源。

0
您可以使用Azure Blob Storage来存储任何文件类型。
如下所示,获取任何文件的文件名、文件流、MIME类型和文件数据。
        var fileName = Path.GetFileName(@"C:\ConsoleApp1\Readme.pdf");
        var fileStream = new FileStream(fileName, FileMode.Create);
        string mimeType = MimeMapping.MimeUtility.GetMimeMapping(fileName);
        byte[] fileData = new byte[fileName.Length];

        objBlobService.UploadFileToBlobAsync(fileName, fileData, mimeType);

这是上传文件到 Azure Blob 的主要方法。
    private async Task<string> UploadFileToBlobAsync(string strFileName, byte[] fileData, string fileMimeType)
    {
        // access key will be available from Azure blob - "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=;EndpointSuffix=core.windows.net"
        CloudStorageAccount csa = CloudStorageAccount.Parse(accessKey);
        CloudBlobClient cloudBlobClient = csa.CreateCloudBlobClient();
        string containerName = "my-blob-container"; //Name of your Blob Container
        CloudBlobContainer cbContainer = cloudBlobClient.GetContainerReference(containerName);
        string fileName = this.GenerateFileName(strFileName);

        if (await cbContainer.CreateIfNotExistsAsync())
        {
            await cbContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
        }

        if (fileName != null && fileData != null)
        {
            CloudBlockBlob cbb = cbContainer.GetBlockBlobReference(fileName);
            cbb.Properties.ContentType = fileMimeType;
            await cbb.UploadFromByteArrayAsync(fileData, 0, fileData.Length);
            return cbb.Uri.AbsoluteUri;
        }
        return "";
    }

这是参考 URL。确保你安装了这些Nuget包。
Install-Package WindowsAzure.Storage 
Install-Package MimeMapping

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接