private void SetReponseHeaders(string fileId, DateTimeOffset?expires) { if (expires != null) { Response.SetHeader(HeaderConstants.UploadExpires, _expirationHelper.FormatHeader(expires)); } Response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue); Response.SetHeader(HeaderConstants.Location, $"{Context.Configuration.UrlPath.TrimEnd('/')}/{fileId}"); }
internal override async Task Invoke() { await WriteUploadLengthIfDefered(); var guardedStream = new ClientDisconnectGuardedReadOnlyStream(Request.Body, CancellationTokenSource.CreateLinkedTokenSource(CancellationToken)); var bytesWritten = await Store.AppendDataAsync(Request.FileId, guardedStream, guardedStream.CancellationToken); if (guardedStream.CancellationToken.IsCancellationRequested) { return; } var expires = _expirationHelper.IsSlidingExpiration ? await _expirationHelper.SetExpirationIfSupported(Request.FileId, CancellationToken) : await _expirationHelper.GetExpirationIfSupported(Request.FileId, CancellationToken); if (!await MatchChecksum()) { await Response.Error((HttpStatusCode)460, "Header Upload-Checksum does not match the checksum of the file"); return; } var fileOffset = long.Parse(Request.GetHeader(HeaderConstants.UploadOffset)); Response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue); Response.SetHeader(HeaderConstants.UploadOffset, (fileOffset + bytesWritten).ToString()); if (expires.HasValue) { Response.SetHeader(HeaderConstants.UploadExpires, _expirationHelper.FormatHeader(expires)); } Response.SetStatus(HttpStatusCode.NoContent); if (await FileIsComplete(Request.FileId, fileOffset, bytesWritten)) { if (!await IsPartialUpload()) { await EventHelper.NotifyFileComplete(Context); } } }
internal override async Task Invoke() { var metadataString = Request.GetHeader(HeaderConstants.UploadMetadata); var metadata = Metadata.Parse(metadataString); string fileId; DateTimeOffset?expires = null; var onBeforeCreateResult = await EventHelper.Validate <BeforeCreateContext>(Context, ctx => { ctx.Metadata = metadata; ctx.UploadLength = Request.UploadLength; ctx.FileConcatenation = UploadConcat.Type; }); if (onBeforeCreateResult == ResultType.StopExecution) { return; } fileId = await HandleCreationOfConcatFiles(Request.UploadLength, metadataString, metadata); if (IsPartialFile()) { expires = await _expirationHelper.SetExpirationIfSupported(fileId, CancellationToken); } Response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue); Response.SetHeader(HeaderConstants.Location, $"{Context.Configuration.UrlPath.TrimEnd('/')}/{fileId}"); if (expires != null) { Response.SetHeader(HeaderConstants.UploadExpires, _expirationHelper.FormatHeader(expires)); } Response.SetStatus(HttpStatusCode.Created); }