Skip to content

Commit

Permalink
fix problem if no file stream is in current http request
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Müller committed Feb 17, 2016
1 parent 70ab0d1 commit 223b747
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ChunkedFileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal void Save(
{
using (Stream stream = new FileStream(chunkFileName, FileMode.Create))
{
inputStream.CopyTo(stream); //, _chunkUploadParameter.CurrentChunkSize);
inputStream.CopyTo(stream);
}
}
catch (Exception exception)
Expand Down
13 changes: 10 additions & 3 deletions src/ChunkedFileUploadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,23 @@ private void CheckIfChunkExistAndIsComplete(
context.Response.StatusCode = fileManager.Exists() ? 200 : 204;
}

private void HandleUploadedChunk(HttpContext context, ChunkUploadParameter chunkUploadParameter)
private void HandleUploadedChunk(
HttpContext context,
ChunkUploadParameter chunkUploadParameter)
{
var fileManager = new FileChunk(UploadBasePath, chunkUploadParameter);

if (context.Request.Files.Count == 0)
{
context.Response.StatusCode = 400;
return;
}

fileManager.Save(context.Request.Files[0].InputStream);

if (fileManager.CheckIfAllChunksUploaded() && fileManager.MergeAllChunks(TargetPath))
{
OnUploadSucceeded(chunkUploadParameter);
}

context.Response.StatusCode = 201;
}

Expand Down

0 comments on commit 223b747

Please sign in to comment.