diff --git a/app/controllers/chunks_controller.rb b/app/controllers/chunks_controller.rb
index 013100214b845aecc51481af0add02ca73f545ef..21bff764228038f88931b3958befcf5d21510c60 100644
--- a/app/controllers/chunks_controller.rb
+++ b/app/controllers/chunks_controller.rb
@@ -38,9 +38,9 @@ class ChunksController < ApplicationController
     currentSize = params[:resumableChunkNumber].to_i * params[:resumableChunkSize].to_i
     filesize = params[:resumableTotalSize].to_i
 
-    #When all chunks are uploaded
-    if (currentSize + params[:resumableCurrentChunkSize].to_i) >= filesize
 
+    #When all chunks are uploaded
+    if params[:resumableChunkNumber].to_i >= params[:resumableTotalChunks].to_i
       #Create a target file
       File.open(resumable_filename, "a") do |target|
         #Loop trough the chunks
@@ -58,7 +58,6 @@ class ChunksController < ApplicationController
         end
         puts "File saved to #{resumable_filename}"
       end
-
       publisher = LearningObjectPublisher.new(DspaceService.create_client)
       publisher.post @learning_object, resumable_filename
     end