Created
May 28, 2020 17:46
-
-
Save joncloud/9f2281ad9787254d5f4ad8b3d091060d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.Storage; | |
using Microsoft.Azure.Storage.File; | |
using System; | |
class Program | |
{ | |
const string ConnectionString = "UseDevelopmentStorage=true"; | |
const string ShareReferenceName = "something"; | |
static void Main(string[] args) | |
{ | |
var uploadUri = CreateTemporaryUploadUri("jon.txt"); | |
// Client code | |
var cloudFile = new CloudFile(uploadUri); | |
cloudFile.UploadText("abc"); | |
} | |
// Server code | |
static Uri CreateTemporaryUploadUri(string fileName) | |
{ | |
var storageAccount = CloudStorageAccount.Parse(ConnectionString); | |
var fileClient = storageAccount.CreateCloudFileClient(); | |
var shareReference = fileClient.GetShareReference(ShareReferenceName); | |
var file = shareReference.GetRootDirectoryReference().GetFileReference(fileName); | |
var signature = file.GetSharedAccessSignature(new SharedAccessFilePolicy | |
{ | |
Permissions = SharedAccessFilePermissions.Create | SharedAccessFilePermissions.Write, | |
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(5) | |
}); | |
return new UriBuilder(file.Uri) | |
{ | |
Query = signature | |
}.Uri; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Azure.Storage.File" Version="11.1.6" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment