从上传相机照片流进WP7蔚蓝的blob(Uploading a photo stream from

2019-09-16 19:31发布

我有一个使用手机拍照上传拍摄的照片,以天蓝色的斑点以下简单的申请页面:

public partial class AddReport : PhoneApplicationPage
{
    // blobs stuff
    string storageAccount = "MYACCOUNT";
    string storageKey = "MYKEY";
    string blobServiceUri = "http://MYACCOUNT.blob.core.windows.net";
    CloudBlobClient blobClient;

    private Report newReport;
    public AddReport()
    {
        InitializeComponent();   
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        //base.OnNavigatedTo(e);

        newReport = new Report();
        var credentials = new StorageCredentialsAccountAndKey(storageAccount, storageKey);
        blobClient = new CloudBlobClient(blobServiceUri, credentials);
    }

    private void TakePhotoClick(object sender, EventArgs eventArgs)
    {
        //The camera chooser used to capture a picture.
        CameraCaptureTask ctask;

        //Create new instance of CameraCaptureClass
        ctask = new CameraCaptureTask();

        //Create new event handler for capturing a photo
        ctask.Completed += new EventHandler<PhotoResult>(ctask_Completed);

        //Show the camera.
        ctask.Show();

    }

    void ctask_Completed(object sender, PhotoResult e)
    {

        if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
        {

            WriteableBitmap CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
            UploadToBlobContainer(e.ChosenPhoto);
        }
        else
        {
            //user decided not to take a picture
        }
    }
    private void UploadToBlobContainer(System.IO.Stream stream)
    {
        string containerName = "reportsPhotos";
        var container = blobClient.GetContainerReference(containerName);

        container.CreateIfNotExist(true, r =>
            Dispatcher.BeginInvoke(() =>
            {
                var blobName = "report" + newReport.ReportId.ToString();
                var blob = container.GetBlobReference(blobName);
                blob.Metadata["ReportId"] = newReport.ReportId.ToString();
                blob.UploadFromStream(stream, r2 =>
                    Dispatcher.BeginInvoke(() =>
                    {
                         newReport.Photo = container.Uri + "/" + blobName;
                    }));
            }));

    }
}

这是一个简单的例子,我不使用SAS来验证,而不是我保存在应用程序本身的键(这只是用于测试目的),也是我的斑点是公开的。

当我在调试模式下运行似乎一切正常,但照片不会被上传到BLOB。 另外,我不知道我该怎么调试这个,看看是否有从团块服务的任何错误。

谁能告诉我什么可能是错误的?

EDIT1:似乎没有被创建或者容器。 我已经证实了这一点用天蓝色的斑点探险

EDIT2:我收到一个System.Net.WebException : "The remote server returned an error: NotFound."

Answer 1:

长时间后,我终于发现,问题是这一行:

string containerName = "reportsPhotos";

据这里的容器名称的所有字母必须是小写 。 它更改为reportsphotos解决问题

这是值得花时间。



Answer 2:

你能尝试只是在做它像这样,而不是:

// Retrieve storage account from connection-string
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

// Create the blob client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob"
CloudBlob blob = container.GetBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blob.UploadFromStream(fileStream);
} 

这是来自:

http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/#upload-blob



文章来源: Uploading a photo stream from camera into azure blob in WP7