【发布时间】:2020-02-26 09:27:58
【问题描述】:
我一直在尝试许多不同的方法来将非常大的视频文件 (8GB) 放入 Azure 存储容器中。
我采用的解决方案是使用 Azure Storage REST API 从 Angular 8 组件直接上传。
这适用于较小的文件,但是当我尝试上传 8GB 文件时,它始终以大约 8% 的速度失败,并出现以下错误:
我不确定我错过了什么。这是我的代码:
component.ts
onFileChange(event) {
this.currentFile = event.target.files[0];
this.upload();
}
upload() {
this.uploading = true;
this.percentComplete = 1;
let url = this.uploadUrl.split('?');
let uploadUrl = url[0] + '/' + this.currentFile.name + '?' + url[1];
const req = new HttpRequest('PUT', uploadUrl, this.currentFile, {
reportProgress: true,
headers: new HttpHeaders({ 'x-ms-blob-type': 'BlockBlob' })
});
this.http.request(req).subscribe(event => {
// Via this API, you get access to the raw event stream.
// Look for upload progress events.
if (event.type === HttpEventType.UploadProgress) {
// This is an upload progress event. Compute and show the % done:
let percentDone = Math.round((100 * event.loaded) / event.total);
if (percentDone === 0) {
percentDone = 1;
}
console.log(event.loaded + ' of ' + event.total);
this.percentComplete = percentDone;
} else if (event instanceof HttpResponse) {
this.uploading = false;
if (event.status === 201) {
this.successEventHandler(event);
}
}
});
}
html
<input [promiseBtn]="uploading" (change)="onFileChange($event)" id="fileAttachmentBtn" name="file-attachment" type="file" class="file-attachment-btn__label" />
【问题讨论】:
-
您确定没有达到
PUT操作的块 Blob 大小限制吗?The maximum size for a block blob created via Put Blob is 256 MB for version 2016-05-31 and later, and 64 MB for older versions. If your blob is larger than 256 MB for version 2016-05-31 and later, or 64 MB for older versions, you must upload it as a set of blocks.docs.microsoft.com/en-us/rest/api/storageservices/put-blob
标签: angular rest file-upload azure-blob-storage