protected function copyToStorage(File $file, FileKey $fileKey)
    {
        $storage = $this->getStorage($fileKey->getStorageName());
        $storagePath = $this->getStoragePath($storage, $fileKey);
        
        $filesystem = $storage->getFilesystem();
        if (!$filesystem->has($storagePath))
        {
            $size = $file->getSize();
            $writtenSize = $filesystem->write($storagePath, file_get_contents($file->getRealPath()));
            
            if ($writtenSize != $size)
            {
                throw new CouldNotWriteToStorageException('Error copying file ' . $file->getRealPath() . ' to storage');
            }
        }
    }