private static void UploadBlobChunk(CloudBlobContainer blobContainer, ResumableRequest request) { var blockBlob = blobContainer.GetBlockBlobReference(request.ResumableFilename); blockBlob.Properties.ContentType = request.ResumableType; blockBlob.PutBlock(GetChunkId(request.ResumableChunkNumber - 1), request.FileStream, null); if (request.ResumableChunkNumber != request.ResumableTotalChunks) return; var ids = new string[request.ResumableTotalChunks]; for (var i = 0; i < request.ResumableTotalChunks; i++) { ids[i] = GetChunkId(i); } blockBlob.PutBlockList(ids); }
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { if (bindingContext.ModelType != typeof(ResumableRequest)) { return false; } try { var request = new ResumableRequest(); foreach (var queryParamater in actionContext.Request.GetQueryNameValuePairs()) {//int resumableChunkNumber, int resumableChunkSize, int resumableCurrentChunkSize, int resumableTotalSize, //string resumableType, string resumableIdentifier, string resumableFilename, string resumableRelativePath, //int resumableTotalChunks switch (queryParamater.Key) { case "resumableChunkNumber": request.ResumableChunkNumber = int.Parse(queryParamater.Value); break; case "resumableChunkSize": request.ResumableChunkSize = int.Parse(queryParamater.Value); break; case "resumableCurrentChunkSize": request.ResumableCurrentChunkSize = int.Parse(queryParamater.Value); break; case "resumableTotalSize": request.ResumableTotalSize = int.Parse(queryParamater.Value); break; case "resumableType": request.ResumableType = queryParamater.Value; break; case "resumableIdentifier": request.ResumableIdentifier = queryParamater.Value; break; case "resumableFilename": request.ResumableFilename = queryParamater.Value; break; case "resumableRelativePath": request.ResumableRelativePath = queryParamater.Value; break; case "resumableTotalChunks": request.ResumableTotalChunks = int.Parse(queryParamater.Value); break; default: break; } } request.FileStream = actionContext.Request.Content.ReadAsStreamAsync().Result; bindingContext.Model = request; return true; } catch (Exception) { return false; } }