我是Xamarin開發新手。我正在使用Azure存儲桶在Android移動應用中上傳文件。 爲了測試目的,我構建了無需中斷即可成功上傳Azure存儲桶上的文件的控制檯應用程序。 但是,當我試圖從移動開發中創建訪問令牌時,它會卡住並給我超時異常。如果我從控制檯應用程序創建令牌並將該令牌用於文件上傳,則會給我另一個例外,如「找不到佔位符」。 正如我所料,我需要一個用於代幣生成的移動服務,如果您有任何想法,請與我分享您的意見,這將是非常有益的。 我還在上傳用於Android移動開發的代碼。Xamarin中的Azure文件同步
[Activity(Label = "WedAndroidApp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
//string sas = "https://supplypark.blob.core.windows.net/transaction-images?sv=2015-04-05&sr=c&sig=iJ8CZOi%2BktarlmrbZVHK7rYLdMOnKCeBjuPqjrrkGnM%3D&se=2016-06-09T14%3A21%3A49Z&sp=rwdl";
string sas_token = "https://supplypark.blob.core.windows.net/transaction-images?sv=2015-04-05&sr=c&sig=AeWe8rghAlKz77Xh%2BUM6S46AuUQzAaD2djqhaW9wdN8%3D&se=2016-06-09T14%3A21%3A49Z&sp=rwdl";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
//button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
button.Click += async delegate {
button.Text = string.Format("{0} clicks!", count++);
await UseContainerSAS(sas_token);
};
}
static async Task UseContainerSAS(string sas)
{
//Try performing container operations with the SAS provided.
//Return a reference to the container using the SAS URI.
CloudBlobContainer container = new CloudBlobContainer(new Uri(sas));
string date = DateTime.Now.ToString();
try
{
//Write operation: write a new blob to the container.
CloudBlockBlob blob = container.GetBlockBlobReference("tdi" + date + ".txt");
string blobContent = "This blob was created with a shared access signature granting write permissions to the container. ";
MemoryStream msWrite = new
MemoryStream(Encoding.UTF8.GetBytes(blobContent));
msWrite.Position = 0;
using (msWrite)
{
await blob.UploadFromStreamAsync(msWrite);
}
Console.WriteLine("Write operation succeeded for SAS " + sas);
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine("Write operation failed for SAS " + sas);
Console.WriteLine("Additional error information: " + e.Message);
Console.WriteLine();
}
}
}
我正在關注這個https://azure.microsoft.com/en-in/documentation/articles/storage-xamarin-blob-storage/的Azure移動開發。但Azure存儲依賴關係不能從neget包獲取下載。 –
你好,夥計們,我解決了這個問題。如果您遇到安裝依賴關係的問題,請使用包控制檯管理器來安裝依賴關係。請按照下列步驟操作: - 「Install-Package WindowsAzure.Storage -Version 4.4.1-preview -Pre」 –