精细上传器Azure上传网址正在更改

时间:2017-09-19 00:37:32

标签: azure fine-uploader asp.net-core-1.1

我让我的项目在Core 1中工作,但当我更改为Core 2时,不再将图像上传到Azure。我得到404响应代码和“将文件发送到Azure的问题”消息。从服务器返回正确的URL,但是,finuploader在Front

中调用带有当前URL的URL

返回404的chrome Console中的URL显示为

  

https://localhost:44348/House/%22https://Customstorage.blob.core.windows.net/images/b0975cc7-fae5-4130-bced-c26272d0a21c.jpeg?sv=2017-04-17&sr=b&sig=UFUEsHT1GWI%2FfMd9cuHmJsl2j05W1Acux52UZ5IsXso%3D&se=2017-09-16T04%3A06%3A36Z&sp=rcwd%22

这被添加到某个地址的网址

  

https://localhost:44348/House/%22

我用

创建SAS
 public async Task<string> SAS(string bloburi, string name)
    {
CloudStorageAccount storageAccount = new CloudStorageAccount(
 new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
 "<storage-account-name>",
 "<access-key>"), true)

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

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

return await Task.FromResult<string>(GetBlobSasUri(container, bloburi));

}

private static string GetBlobSasUri(CloudBlobContainer container, string blobName, string policyName = null)
    {

        string sasBlobToken;
        // Get a reference to a blob within the container.
        // Note that the blob may not exist yet, but a SAS can still be created for it.
        var uri = new Uri(blobName);
        //get the name of the file from the path
        string filename = System.IO.Path.GetFileName(uri.LocalPath);

        CloudBlockBlob blob = container.GetBlockBlobReference(filename);
        if (policyName == null)
        {
            // Create a new access policy and define its constraints.
            // Note that the SharedAccessBlobPolicy class is used both to define the parameters of an ad-hoc SAS, and 
            // to construct a shared access policy that is saved to the container's shared access policies. 
            SharedAccessBlobPolicy adHocSAS = new SharedAccessBlobPolicy()
            {
                // When the start time for the SAS is omitted, the start time is assumed to be the time when the storage service receives the request. 
                // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
                Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Delete
            };
            // Generate the shared access signature on the blob, setting the constraints directly on the signature.
            sasBlobToken = blob.GetSharedAccessSignature(adHocSAS);
        }
        else
        {
            // Generate the shared access signature on the blob. In this case, all of the constraints for the
            // shared access signature are specified on the container's stored access policy.
            sasBlobToken = blob.GetSharedAccessSignature(null, policyName);
        }
        // Return the URI string for the container, including the SAS token.
        return blob.Uri + sasBlobToken;
    }

Fine-uploader -

var uploader = new qq.azure.FineUploader({
        element: document.getElementById('uploader'),
template: 'qq-template',
        autoUpload: false,
        request: {
            endpoint:'https://customstorage.blob.core.windows.net/images'
        },
        signature: {
            endpoint: '/House/SAS'
        },
        uploadSuccess: {
            endpoint: '/House/UploadImage'
        }

    });

0 个答案:

没有答案