|
@@ -607,7 +607,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
// Return the URI string for the container, including the SAS token.
|
|
// Return the URI string for the container, including the SAS token.
|
|
return (blobContainer.Uri.ToString(), sasContainerToken);
|
|
return (blobContainer.Uri.ToString(), sasContainerToken);
|
|
}
|
|
}
|
|
- public async Task<KeyValuePair<string, object>> GetContainerSasUri(BlobSas blobSas, bool isRead)
|
|
|
|
|
|
+ public async Task<dynamic> GetContainerSasUri(BlobSas blobSas, bool isRead)
|
|
{
|
|
{
|
|
CloudBlobContainer blobContainer;
|
|
CloudBlobContainer blobContainer;
|
|
if (blobSas.role == "system")
|
|
if (blobSas.role == "system")
|
|
@@ -624,7 +624,6 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
// to construct a shared access policy that is saved to the container's shared access policies.
|
|
// to construct a shared access policy that is saved to the container's shared access policies.
|
|
DateTimeOffset dateTime = DateTime.UtcNow.AddHours(1);
|
|
DateTimeOffset dateTime = DateTime.UtcNow.AddHours(1);
|
|
long time = dateTime.ToUnixTimeMilliseconds();
|
|
long time = dateTime.ToUnixTimeMilliseconds();
|
|
- SharedAccessBlobPolicy adHocSAS = null;
|
|
|
|
SharedAccessBlobPolicy adHocPolicy = null;
|
|
SharedAccessBlobPolicy adHocPolicy = null;
|
|
if (isRead)
|
|
if (isRead)
|
|
{
|
|
{
|
|
@@ -649,8 +648,8 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
}
|
|
}
|
|
// Generate the shared access signature on the container, setting the constraints directly on the signature.
|
|
// Generate the shared access signature on the container, setting the constraints directly on the signature.
|
|
string sasContainerToken = blobContainer.GetSharedAccessSignature(adHocPolicy, null);
|
|
string sasContainerToken = blobContainer.GetSharedAccessSignature(adHocPolicy, null);
|
|
- KeyValuePair<string, object> dict = new KeyValuePair<string, object>( blobContainer.Name, new { url = blobContainer.Uri, sas = sasContainerToken, timeout = time } );
|
|
|
|
- return dict;
|
|
|
|
|
|
+
|
|
|
|
+ return new { url = blobContainer.Uri, sas = sasContainerToken, timeout = time };
|
|
}
|
|
}
|
|
public async Task<Dictionary<string,object>> GetBlobSasUri(BlobSas blobSas,bool isRead) {
|
|
public async Task<Dictionary<string,object>> GetBlobSasUri(BlobSas blobSas,bool isRead) {
|
|
string sasBlobToken;
|
|
string sasBlobToken;
|
|
@@ -823,7 +822,24 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
}
|
|
}
|
|
return blob.Uri + sasBlobToken;
|
|
return blob.Uri + sasBlobToken;
|
|
}
|
|
}
|
|
|
|
+ public async Task<dynamic> GetBlobSasUriRead(string containerName, string blobName)
|
|
|
|
+ {
|
|
|
|
+ string sasBlobToken;
|
|
|
|
+ blobContainer = await GetContainer(containerName);
|
|
|
|
+ CloudBlockBlob blob = blobContainer.GetBlockBlobReference(blobName);
|
|
|
|
+ DateTimeOffset dateTime = DateTime.UtcNow.AddHours(1);
|
|
|
|
+ long time = dateTime.ToUnixTimeMilliseconds();
|
|
|
|
+ SharedAccessBlobPolicy adHocSAS = new SharedAccessBlobPolicy()
|
|
|
|
+ {
|
|
|
|
+ SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
|
|
|
|
+ SharedAccessExpiryTime = dateTime,
|
|
|
|
+ Permissions = SharedAccessBlobPermissions.Read
|
|
|
|
+ };
|
|
|
|
+ sasBlobToken = blob.GetSharedAccessSignature(adHocSAS);
|
|
|
|
+ return new { url = blob.Uri, sas = sasBlobToken, timeout = time };
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
private async Task<CloudBlobContainer> CreateContainer(string containerName)
|
|
private async Task<CloudBlobContainer> CreateContainer(string containerName)
|
|
{
|
|
{
|
|
@@ -833,7 +849,18 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
await container.CreateIfNotExistsAsync();
|
|
await container.CreateIfNotExistsAsync();
|
|
return container;
|
|
return container;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ private async Task<CloudBlobContainer> GetContainer(string containerName)
|
|
|
|
+ {
|
|
|
|
+ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_options.ConnectionString);
|
|
|
|
+ CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
|
|
|
|
+ CloudBlobContainer container = blobClient.GetContainerReference(containerName);
|
|
|
|
+ bool a = await container.ExistsAsync();
|
|
|
|
+ if (!a) {
|
|
|
|
+ throw new BizException("容器不存在!",ResponseCode.PARAMS_ERROR);
|
|
|
|
+ }
|
|
|
|
+ // await container.CreateIfNotExistsAsync();
|
|
|
|
+ return container;
|
|
|
|
+ }
|
|
|
|
|
|
public async Task Deleteblob(string azureBlobSAS)
|
|
public async Task Deleteblob(string azureBlobSAS)
|
|
{
|
|
{
|