我已经花了很长时间尝试将一些东西上传到我用Xamarin.ios项目设置的Azure blob容器中。
我不确定为什么它不起作用,并探索了许多不同的选择。
每当尝试在Viewcontroller中引用LimaBeans时,我都会得到CS0426。
陷入困境。
这是我的View Controller
using System;
using System.IO;
using UIKit;
namespace storingbuttondataaaa
{
public partial class ViewController : UIViewController
{
protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
partial void FractureBtn_TouchUpInside(UIButton sender)
{
//get text box data
var name = FractureBtn;
string call = ("call 911, especially if blood is spraying everywhere!");
string line = string.Format("{0},{1}", name, call);
//Store the Information.
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(documents, "HealthJournal.txt");
File.WriteAllText(filename, line);
;
}
partial void HandleAddClicked_TouchUpInside(UIButton sender)
{
activityIndicator.StartAnimating();
new BlobUpload.LimaBeans();
}
}
}
这是我的Blob上传任务:
using System;
using System.Diagnostics.Contracts;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
namespace storingbuttondataaaa
{
public class BlobUpload
{
public BlobUpload()
{
}
public static async Task LimaBeans(string localPath)
{
Contract.Ensures(Contract.Result<Task>() != null);
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=itsmypersonalkey");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("submittedreqforbd");
// Create the container if it doesn't already exist.
await container.CreateIfNotExistsAsync();
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
//await blockBlob.UploadFromFileAsync(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
await blockBlob.UploadTextAsync("My Head Just Exploaded!");
}
}
}
怎么了?我快要放弃了!
答案 0 :(得分:0)
未找到用于实现部分方法ViewController.FractureBtn_TouchUpInside(UIButton)声明的定义声明
我们应该在另一个局部类中定义此方法的声明,如下所示:
partial void FractureBtn_TouchUpInside(UIButton sender);
要将本地文件上传到Azure,我们可以执行以下操作:
/// <summary>
/// Upload file to Blob
/// </summary>
/// <param name="path">path of local file. For example: C:\Users\leel2\Desktop\333.txt</param>
/// <param name="blobName">For example: 333.txt</param>
/// <param name="containerName"></param>
public static void UploadBlob(string path, string blobName, string containerName)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=xxxxxxxx");
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerName);
container.CreateIfNotExists();
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
blob.UploadFromFile(path);
}