2

この質問が重複として解釈される可能性があることは知っていますが、blop サービスを機能させることはできません。msdnの標準的な例に従いました。コードに実装しましたが、例に従いました。この例で提供されているスクリプトを使用して MobileService を取得し、開いているプロパティを持つ BLOB を挿入できます。次に、このコードを使用して画像を BLOB ストレージにアップロードします。

 BitmapImage bi = new BitmapImage();
 MemoryStream stream = new MemoryStream();
 if (bi != null)
 {
      WriteableBitmap bmp = new WriteableBitmap((BitmapSource)bi);
      bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
 }

 if (!string.IsNullOrEmpty(uploadImage.SasQueryString))
 {
       // Get the URI generated that contains the SAS 
       // and extract the storage credentials.
       StorageCredentials cred = new StorageCredentials(uploadImage.SasQueryString);
       var imageUri = new Uri(uploadImage.ImageUri);

       // Instantiate a Blob store container based on the info in the returned item.
       CloudBlobContainer container = new CloudBlobContainer(
       new Uri(string.Format("https://{0}/{1}",
       imageUri.Host, uploadImage.ContainerName)), cred);

       // Upload the new image as a BLOB from the stream.
       CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(uploadImage.ResourceName);
       await blobFromSASCredential.UploadFromStreamAsync(stream);//error!

       // When you request an SAS at the container-level instead of the blob-level,
       // you are able to upload multiple streams using the same container credentials.

       stream = null;
 }

このコードのエラーとマークされたポイントで、次のエラーでエラーが発生しています。

+       ex  {Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.

スクリプトから文字列を返すコードは次のとおりであるため、わかりません。

// Generate the upload URL with SAS for the new image.
var sasQueryUrl = blobService.generateSharedAccessSignature(item.containerName, 
item.resourceName, sharedAccessPolicy);

// Set the query string.
item.sasQueryString = qs.stringify(sasQueryUrl.queryString);

// Set the full path on the new new item, 
// which is used for data binding on the client. 
item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;

もちろん、これはブロブ ストレージの構造を完全に把握していないことも示しています。したがって、どんな助けでも大歓迎です。

コメント の詳細 サーバー コードから、少なくとも 5 分間のパブリック ノートを作成する必要があります。したがって、問題にはなりません。私のサーバースクリプトはリンクと同じです。しかし、ここで複製されます:

var azure = require('azure');
var qs = require('querystring');
var appSettings = require('mobileservice-config').appSettings;

function insert(item, user, request) {
// Get storage account settings from app settings. 
var accountName = appSettings.STORAGE_ACCOUNT_NAME;
var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
var host = accountName + '.blob.core.windows.net';

if ((typeof item.containerName !== "undefined") && (
item.containerName !== null)) {
    // Set the BLOB store container name on the item, which must be lowercase.
    item.containerName = item.containerName.toLowerCase();

    // If it does not already exist, create the container 
    // with public read access for blobs.        
    var blobService = azure.createBlobService(accountName, accountKey, host);
    blobService.createContainerIfNotExists(item.containerName, {
        publicAccessLevel: 'blob'
    }, function(error) {
        if (!error) {

            // Provide write access to the container for the next 5 mins.        
            var sharedAccessPolicy = {
                AccessPolicy: {
                    Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
                    Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
                }
            };

            // Generate the upload URL with SAS for the new image.
            var sasQueryUrl = 
            blobService.generateSharedAccessSignature(item.containerName, 
            item.resourceName, sharedAccessPolicy);

            // Set the query string.
            item.sasQueryString = qs.stringify(sasQueryUrl.queryString);

            // Set the full path on the new new item, 
            // which is used for data binding on the client. 
            item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;

        } else {
            console.error(error);
        }

        request.execute();
    });
} else {
    request.execute();
}
}

写真のアイデアは、アプリの他のユーザーが写真にアクセスできるようにすることです。私が理解している限り、私はそれを公開しましたが、5分間だけ公開を書きます. ユーザーを認証する必要がある mobileservice テーブルに保存する blob の URL は、ストレージで同じ安全性を確保したいと考えています。しかし、これが達成されたかどうかわかりませんか?ばかげた質問をして申し訳ありませんが、自分で解決できなかったので、「ばかげているように見える」必要があります:)

4

1 に答える 1

3

誰かがここで助けを必要としている場合。私にとっての問題はウリでした。https ではなく、http である必要があります。その後、アップロードにエラーはありませんでした。

しかし、ツールボックスからのテスト イメージ コントロールでもイメージを表示することはできませんでした。問題は、ストリームを最初に設定する必要があったことです:

stream.Seek(0, SeekOrigin.Begin);

その後、アップロードが機能し、データを取得できました。

于 2014-04-01T12:06:18.897 に答える