protected function process($tmp_name, $name, $size, $type, $error, $index = 0, $content_range = null)
    {
        $this->fileContainer = $file = new File($tmp_name, $name);
        $file->name = $this->getFilename($name, $type, $index, $content_range, $tmp_name);
        $file->size = $this->fixIntegerOverflow(intval($size));
        $completed = false;

        if ($file->name) { //since the md5 filename generator would return false if it's allowDuplicate property is set to false and the file already exists.

            if ($this->validate($tmp_name, $file, $error, $index)) {
                // Now that we passed the validation, we can work with the file
                $upload_path = $this->pathresolver->getUploadPath();
                $file_path = $this->pathresolver->getUploadPath($file->name);
                $append_file = $content_range && $this->filesystem->isFile($file_path) && $file->size > $this->getFilesize($file_path);

                if ($tmp_name && $this->filesystem->isUploadedFile($tmp_name)) {
                    // This is a normal upload from temporary file
                    if ($append_file) {
                        // Adding to existing file (chunked uploads)
                        $this->filesystem->writeToFile($file_path, $this->filesystem->getFileStream($tmp_name), true);
                    } else {
                        // Upload full file
                        $this->filesystem->moveUploadedFile($tmp_name, $file_path);
                    }
                } else {
                    // This is a PUT-type upload
                    $this->filesystem->writeToFile($file_path, $this->filesystem->getInputStream(), $append_file);
                }

                $file_size = $this->getFilesize($file_path, $append_file);

                if ($this->logger) {
                    $this->logger->debug('Processing ' . $file->name, [
                        'File path' => $file_path,
                        'File object' => $file,
                        'Append to file?' => $append_file,
                        'File exists?' => $this->filesystem->isFile($file_path),
                        'File size' => $file_size,
                    ]);
                }

                if ($file->size == $file_size) {
                    // Yay, upload is complete!
                    $completed = true;
                } else {
                    if (! $content_range) {
                        // The file is incomplete and it's not a chunked upload, abort
                        $this->filesystem->unlink($file_path);
                        $file->error = 'abort';
                    }
                }

                $file = new File($file_path, $name);
                $file->completed = $completed;
                $file->size = $file_size;

                if ($completed) {
                    $this->processCallbacksFor('completed', $file);
                }
            }
        }

        return $file;
    }