public function upload($maxFileSize = null, $acceptFileTypes = null) {
		Configure::write('debug', 0);
		if (!$this->_controller->request->is('ajax') || !$this->_controller->RequestHandler->prefers('json')) {
			throw new BadRequestException(__d('view_extension', 'Invalid request'));
		}

		$uploadDir = $this->getUploadDir();
		if (empty($acceptFileTypes)) {
			$acceptFileTypes = '/.+$/i';
		}

		$opt = [
			'script_url' => '',
			'upload_url' => '',
			'param_name' => 'files',
			'upload_dir' => $uploadDir,
			'max_file_size' => $maxFileSize,
			'image_versions' => [
				'' => ['auto_orient' => false]
			],
			'correct_image_extensions' => false,
			'accept_file_types' => $acceptFileTypes
		];
		$uploadHandler = new UploadHandler($opt, false);

		switch ($this->_controller->request->method()) {
			case 'OPTIONS':
			case 'HEAD':
				$data = $uploadHandler->head(false);
				break;
			case 'GET':
				$data = $uploadHandler->get(false);
				break;
			case 'PATCH':
			case 'PUT':
			case 'POST':
				$data = $uploadHandler->post(false);
				break;
			default:
				throw new MethodNotAllowedException();
		}

		return $data;
	}