Newer
Older
class V1::LearningObjects::ChunksController < ApplicationController
before_action :chunk_service
# GET /learning_objects/:learning_object_id/chunk
def show
if @chunk.exist?
post_file
render status: :not_found # chunk doesnt exists and needs to be uploaded
end
end
# POST /learning_objects/:learning_object_id/chunk
def create
@chunk.save
post_file
end
private
def chunk_service
@chunk = ChunksService.new(chunks_params)
return render status: :unsupported_media_type if @chunk.nil?
return false unless @chunk.concatenated
publisher = LearningObjectPublisher.new(DspaceService.create_client)
publisher.upload @chunk.learning_object, @chunk.resumable_filename
learning_object = LearningObject.find chunks_params[:id]
authorize(learning_object || LearningObject.new, :update?)
end
# Never trust parameters from the scary internet, only allow the white list through.
def chunks_params
params.permit(:id, :file, :resumableIdentifier, :resumableFilename, :resumableChunkNumber, :resumableTotalChunks, :resumableChunkSize, :resumableCurrentChunkSize, :resumableTotalSize, :resumableType, :resumableRelativePath)