1

注: Azure BLOB ストレージに送信する必要がある SAS 文字列の例 (右側の領域にブロック情報が追加されています) を教えてください。それが私が抱えている問題だと思います。各ブロックで Azure に送信される文字列の uri、キーなどの順序を把握する必要があります。

私が達成しようとしているのは、サービスから SAS キーを取得し、ブロックで送信していることを Azure が認識できるように文字列キーを変更し、Web クライアントから sas キーを使用してファイルの個々のブロックを送信することです。 . 各ファイルを 2MB のブロックにチャンクし、それらの 2MB のブロックを一度に JavaScript ライブラリと共に送信しています。したがって、以下のコードの各「ファイル」は、ファイルの 2MB チャンクにすぎません。

問題: サービスから SAS キーを正常に取得し、ブロック チャンク情報が含まれるようにキーを変更し、FIRST チャンクを送信して、BLOB ストレージ サーバーから応答を受け取ることができます。しかし、2 番目のチャンクを送信すると、ブロブ ストレージへのストリームの要求がハングし、最終的にタイムアウトになります。タイムアウトは、特にブロブ ストレージへのストリームに対する 2 番目の要求で発生するようです。このコードのビットはここにあります:

サーバー Web クライアント コード:

    using (Stream requestStream = request.GetRequestStream())
    {
        inputStream.CopyTo(requestStream, file.ContentLength);
    }

2 番目のチャンクがタイムアウトする原因は何ですか? キーのウィンドウが閉じるのが早すぎる可能性がありますか? 以下は私のコードといくつかのスクリーンショットです:

    private void WriteToBlob(HttpPostedFileBase file, string BlockId, FileProp fp)
    {
        var inputStream = file.InputStream;

        Microsoft.WindowsAzure.StorageCredentialsSharedAccessSignature credentials =
            new Microsoft.WindowsAzure.StorageCredentialsSharedAccessSignature(fp.facct);


        string queryString = (new Uri(fp.folderName)).Query;

        string RequestUri = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}{2}&comp=block&blockid={3}",
            fp.folderName, fp.fileName, queryString, Convert.ToBase64String(Encoding.UTF8.GetBytes(BlockId)));

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(RequestUri);
        request.Method = "PUT";
        request.ContentLength = inputStream.Length;
        using (Stream requestStream = request.GetRequestStream())
        {
            inputStream.CopyTo(requestStream, file.ContentLength);
        }

    }

チャンクを Web サーバークライアントに送信する JAVASCRIPT コード:

        var running = 0;
    var chunksize = (Modernizr.blobconstructor) ? uploadChunkSize : null;    //if browser support Blob API
    window.xhrPool = [];
    $('#fileupload').fileupload({
        url: url,
        //formData: [{ name: 'param1', value: 1 }, { name: 'param2', value: 2}],
        singleFileUploads: true, //each file is using an individual XHR request
        //limitMultiFileUploads: 2, //This option is ignored, if singleFileUploads is set to true.
        multipart: true,
        maxChunkSize: chunksize, //server side is in streaming mode
        sequentialUploads: true, //Set this option to true to issue all file upload requests in a sequential order instead of simultaneous requests.
        dataType: 'json',
        autoUpload: true,
        //acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        progressInterval: 100,
        bitrateInterval: 100,
        maxFileSize: uploadFileSizeLimit
    }).on('fileuploadadd', function (e, data) {

        var filename = data.files[0].name;
        var filesize = data.files[0].size;
        if (filesize == 0) {
            var zeroSizeErrMsg = sceneLayoutService.format('This file {filename} is empty please select files again without it. ', { filename: filename });
            sceneLayoutService.showErrorDialog(zeroSizeErrMsg);
            return;
        }

        if (window.availableStorageSize != null && window.availableStorageSize != '') {
            if (filesize > window.availableStorageSize) {
                var overSizeErrMsg = sceneLayoutService.format('File size of {filename} exceeds available storage space in your cloud drive. ', { filename: filename });
                sceneLayoutService.showErrorDialog(overSizeErrMsg);
                return;
            }
        } else {
            alert('Unable to retrieve the storage usage.');
        }

        data.jqXHR = data.submit();
        window.xhrPool.push(data.jqXHR);
        sceneLayoutService.addFileToProgressDialog(data, cancelButton);

    }).on('fileuploadprocessalways', function (e, data) {

    }).on('fileuploadprogressall', function (e, data) {

    }).on('fileuploadsubmit', function (e, data) {

        var filesize = data.files[0].size;
        if (filesize == 0) {
            return false;
        }

        if (window.availableStorageSize != null && window.availableStorageSize != '') {
            if (filesize > window.availableStorageSize) {
                return false;
            }
        }
        $('#dlgProgress').parent().show();
        running++;
        sceneLayoutService.showProgressDialog('Uploading files to ' + currentUser + '\'s Cloud Storage ...', abortAllUploads);
        return true;

    }).on('fileuploaddone', function (e, data) {

        running--;
        updateStorageQuota(function () {
            var usedStorageSize = (window.usedStorageSize != null) ? bytesToSize(window.usedStorageSize, 2) : 0;
            var totalStorageSize = (window.totalStorageSize != null) ? bytesToSize(window.totalStorageSize, 2) : 0;
            var usageFooterStr = sceneLayoutService.format("Using {used} of {total} (%)", { used: usedStorageSize, total: totalStorageSize });
            $('div.dlgProgressFooter').text(usageFooterStr);
        });


        var docGridUrl = window.baseUrl + '/CloudStorage/ChangePage?page=1&rand=' + sceneLayoutService.getRandomString(4);
        $('#docGridPartial').load(docGridUrl, function () {
            grid.init({
                pageNumber: 1,
                url: window.baseUrl + '/CloudStorage/ChangePage',
                sortColumn: '',
                sortDirection: ''
            });
        });

        sceneLayoutService.updateFileUploadFinalStatus(data, 'done');

        if (!data.result.success) {
            debugger;
            var errMsg = "";
            if (data.result != null) {
                if (data.result.message != null) {
                    errMsg += data.result.message;
                }
                if (data.result.error != null)
                    errMsg += data.result.error;
            }
            sceneLayoutService.showErrorDialog(errMsg);
        }
        window.removeXHRfromPool(data);

        if (running == 0) {
            $('#dlgProgress').parent().hide();
            $('#progresses').empty();
        }
    }).on('fileuploadfail', function (e, data) {
        running--;

        sceneLayoutService.updateFileUploadFinalStatus(data, 'fail');

        window.removeXHRfromPool(data);

        if (running == 0) {
            $('#dlgProgress').parent().hide();
            $('#progresses').empty();
        }
    }).on('fileuploadprogress', function (e, data) {

        //XHR upload onProgress event not fired at server-defined intervals/not supported in IE8 and IE9,
        //will be supported in IE10 in terms of XMLHttpRequest Level 2 specification, http://caniuse.com/xhr2
        sceneLayoutService.updateFileUploadProgress(data);
    });

ここに画像の説明を入力

ここに画像の説明を入力

4

1 に答える 1

1

問題は解決された。SAS URI の形式が正しくないことが判明しました。Sas URI (私の場合はコンテナー用) は次のようになります。

http://container_uri/filename?key
于 2013-08-14T09:33:34.043 に答える