Controller/MediaController.php
public function uploadFile($pathname, $name, $categoryId, $progress = null, $chunkSize = 10485760)
        {
            $chunk = 0;
            $chunksTotal = ceil(filesize($pathname) / $chunkSize);
            $fileId = sha1(uniqid('upload', true));
            $fp = fopen($pathname, 'rb');
            if (false === $fp) {
                throw new UploadException('Could not open file "' . $pathname . '" for reading.');
            }
            if ($chunkSize > 10485760) {
                $this->logger->warning('Using a chunk size larger then 10MB is not recommended. Uploading is not guaranteed to work properly.');
            }
            while ($chunkData = fread($fp, $chunkSize)) {
                $result = $this->uploadFileChunked($chunkData, $name, $chunk, $chunksTotal, $fileId, $categoryId);
                if (is_callable($progress)) {
                    try {
                        call_user_func($progress, $chunk + 1, $chunksTotal);
                    } catch (\Exception $e) {
                        $this->logger->warning('Could not report progress due to callback error.', ['message' => $e->getMessage()]);
                    }
                }
                $this->logger->info('Upload progress!', ['part' => $chunk + 1, 'total' => $chunksTotal]);
                if (isset($result['mediaId'])) {
                    return new MediaResponse($result);
                }
                if (isset($result['success']) && false == $result['success']) {
                    throw new UploadException($result['error']['message'], $result['error']['code']);
                }
                if (isset($result['fileId'])) {
                    $fileId = $result['fileId'];
                }
                ++$chunk;
            }
            if ($chunk == $chunksTotal - 1) {
                throw new UploadException('Uploaded all chunks, but something went wrong.');
            }
            if (false === $chunkData) {
                throw new UploadException('Could not read chunk ' . $chunk . ' from file "' . $pathname . '".');
            }
            throw new UploadException('Unknown upload error!');
        }
public function uploadFile($pathname, $name, $categoryId, $progress = null, $chunkSize = 10485760)
        {
            $chunk = 0;
            $chunksTotal = ceil(filesize($pathname) / $chunkSize);
            $fileId = sha1(uniqid('upload', true));
            $fp = fopen($pathname, 'rb');
            if (false === $fp) {
                throw new UploadException('Could not open file "' . $pathname . '" for reading.');
            }
            if ($chunkSize > 10485760) {
                $this->logger->warning('Using a chunk size larger then 10MB is not recommended. Uploading is not guaranteed to work properly.');
            }
            while ($chunkData = fread($fp, $chunkSize)) {
                $result = $this->uploadFileChunked($chunkData, $name, $chunk, $chunksTotal, $fileId, $categoryId);
                if (is_callable($progress)) {
                    try {
                        call_user_func($progress, $chunk + 1, $chunksTotal);
                    } catch (\Exception $e) {
                        $this->logger->warning('Could not report progress due to callback error.', ['message' => $e->getMessage()]);
                    }
                }
                $this->logger->info('Upload progress!', ['part' => $chunk + 1, 'total' => $chunksTotal]);
                if (isset($result['mediaId'])) {
                    return new MediaResponse($result);
                }
                if (isset($result['success']) && false == $result['success']) {
                    throw new UploadException($result['error']['message'], $result['error']['code']);
                }
                if (isset($result['fileId'])) {
                    $fileId = $result['fileId'];
                }
                ++$chunk;
            }
            if ($chunk == $chunksTotal - 1) {
                throw new UploadException('Uploaded all chunks, but something went wrong.');
            }
            if (false === $chunkData) {
                throw new UploadException('Could not read chunk ' . $chunk . ' from file "' . $pathname . '".');
            }
            throw new UploadException('Unknown upload error!');
        }
Upload a new Media to QBank.

Will automatically divide files into chunks if neccessary. The specific breakpoint when chunking occurs is
customizable, but defaults to the recommended maximum. It is also possible to monitor uploading via callbacks.

@param string   $pathname   the pathname of the file to upload
@param string   $name       the name of the new Media
@param int      $categoryId the ID of the Category the new Media should belong to
@param callable $progress   Provides progress monitoring. Callback should have the signature function($chunk, $chunkTotal).
@param int      $chunkSize  The size of chunk during upload. Defaults to the recommended maximum of 10MB.

@throws UploadException thrown if something went wrong during the upload

@return MediaResponse the newly created Media