加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 上传到Azure

发布时间:2020-12-16 07:39:42 所属栏目:asp.Net 来源:网络整理
导读:我在尝试直接将文件上传到azure blob存储时遇到问题.我正在使用ajax调用将发布请求发送到ashx处理程序以上传块中的blob.我遇到的问题是处理程序没有收到从ajax帖子发送的文件块. 我可以看到页面正在通过查看firebug中的请求正确接收帖子, —————————
我在尝试直接将文件上传到azure blob存储时遇到问题.我正在使用ajax调用将发布请求发送到ashx处理程序以上传块中的blob.我遇到的问题是处理程序没有收到从ajax帖子发送的文件块.

我可以看到页面正在通过查看firebug中的请求正确接收帖子,

—————————–265001916915724 Content-Disposition: form-data; >name=”Slice”; filename=”blob” Content-Type: application/octet-stream

我注意到处理程序上的输入流有文件块,包括请求中的其他字节.我试图从输入流中只读取文件块的大小,但这会导致文件损坏.

我从http://code.msdn.microsoft.com/windowsazure/Silverlight-Azure-Blob-3b773e26获得了灵感,我只是将它从MVC3转换为使用标准的aspx.

这是使用ajax将文件块发送到aspx页面的调用,

var sendFile = function (blockLength) {
var start = 0,end = Math.min(blockLength,uploader.file.size),incrimentalIdentifier = 1,retryCount = 0,sendNextChunk,fileChunk;
uploader.displayStatusMessage();
sendNextChunk = function () {
    fileChunk = new FormData();
    uploader.renderProgress(incrimentalIdentifier);
    if (uploader.file.slice) {
        fileChunk.append('Slice',uploader.file.slice(start,end));
    }
    else if (uploader.file.webkitSlice) {
        fileChunk.append('Slice',uploader.file.webkitSlice(start,end));
    }
    else if (uploader.file.mozSlice) {
        fileChunk.append('Slice',uploader.file.mozSlice(start,end));
    }
    else {
        uploader.displayLabel(operationType.UNSUPPORTED_BROWSER);
        return;
    }
    var testcode = 'http://localhost:56307/handler1.ashx?create=0&blockid=' + incrimentalIdentifier + '&filename=' + uploader.file.name + '&totalBlocks=' + uploader.totalBlocks;
    jqxhr = $.ajax({
        async: true,url: testcode,data: fileChunk,contentType: false,processData:false,dataType: 'text json',type: 'POST',error: function (request,error) {
            if (error !== 'abort' && retryCount < maxRetries) {
                ++retryCount;
                setTimeout(sendNextChunk,retryAfterSeconds * 1000);
            }

            if (error === 'abort') {
                uploader.displayLabel(operationType.CANCELLED);
                uploader.resetControls();
                uploader = null;
            }
            else {
                if (retryCount === maxRetries) {
                    uploader.uploadError(request.responseText);
                    uploader.resetControls();
                    uploader = null;
                }
                else {
                    uploader.displayLabel(operationType.RESUME_UPLOAD);
                }
            }

            return;
        },success: function (notice) {
            if (notice.error || notice.isLastBlock) {
                uploader.renderProgress(uploader.totalBlocks + 1);
                uploader.displayStatusMessage(notice.message);
                uploader.resetControls();
                uploader = null;
                return;
            }

            ++incrimentalIdentifier;
            start = (incrimentalIdentifier - 1) * blockLength;
            end = Math.min(incrimentalIdentifier * blockLength,uploader.file.size);
            retryCount = 0;
            sendNextChunk();
        }
    });
};

非常感谢能帮到我的任何事情.

解决方法

是故意的ASPX吗?在 http://localhost:56307/handler1.ashx?create = 0& blockid?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读