Downloading preview file

@param int|string $id ID for downloaded data.
@param string $file File name of downloaded file.
@throws InternalErrorException if downloaded is not exists.
@return CakeRequest Return CakeRequest object for download request.
513685
public function download($id = null, $file = null) {
		$type = $this->_controller->RequestHandler->prefers();
		$exportFileName = null;
		if (method_exists($this->_model, 'getExportFilename')) {
			$exportFileName = $this->_model->getExportFilename($id, true);
		}

		$exportPath = $this->_getExportDir();
		$downloadFile = $exportPath . $file;
		if (!empty($type)) {
			$downloadFile .= '.' . $type;
		}

		if (!file_exists($downloadFile)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid file for downloading'));
		}

		if (!empty($type) && !empty($exportFileName)) {
			$this->_controller->response->type($type);
			$exportFileName .= '.' . $type;
		}
		$responseOpt = [
			'download' => true,
		];
		if (!empty($exportFileName)) {
			if ($this->_controller->request->is('msie')) {
				$exportFileName = rawurlencode($exportFileName);
			}
			$responseOpt['name'] = $exportFileName;
		}
		$this->_controller->response->file($downloadFile, $responseOpt);

		return $this->_controller->response;
	}
604715
public function upload (UploadedFile $file, bool $full = null, string $id = null)
    {
        if (is_null ($file))
            return HCLog::info ('R-UPLOAD-001', trans ('resources::resources.errors.no_resource_selected'));

        DB::beginTransaction ();

        $this->resourceID = $id;

        try {
            $resource = $this->createResourceRecord ($file);
            $this->saveResourceInStorage ($resource, $file);

            //Generating checksum
            if ($resource['size'] <= env ('MAX_CHECKSUM_SIZE', self::MAX_CHECKSUM_SIZE))
                $resource->update (['checksum' => hash_file ('sha256', storage_path ('app/' . $resource['path']))]);

            Artisan::call ('hc:generate-thumbs', ['id' => $resource->id]);
        } catch (\Exception $e) {
            DB::rollback ();

            if (isset($resource))
                $this->removeImageFromStorage ($resource);

            throw new \Exception($e);
        }

        DB::commit ();

        if ($full)
            return $resource->toArray ();

        return [
            'id'  => $resource->id,
            'url' => route ('resource.get', $resource->id),
        ];
    }
304136
public function update($id)
    {
        $file = $this->fileRepo->getById($id);
        if (!empty($file)) {
            $this->authorize('update', $file);
            $input = $this->validator->validate('update');
            $file  = $this->fileRepo->update($file, $input, Auth::user());
            return $this->respondWithSuccess($file, new FileTransformer);
        }
        return $this->respondNotFound();
    }
835456
public static DownloadResponse downloadFile(Drive drive, File file) throws IOException {
    if (file == null) {
      return null;
    }
    
    return downloadFile(drive, file.getId());
  }
1360799
public function download($id = null)
    {
        return $this->response->withFile($this->Photos->get($id)->path, ['download' => true]);
    }
175131
public function getFile(string $id): ?FileResponse
	{
		$log = $this->getLog($id);
		if ($log) {
			$file = $log->name;
			if (Strings::endsWith($file, '.html')) {
				$contentType = 'text/html';
			} else {
				$contentType = 'text/plain';
			}
			return new FileResponse($this->path . $file, $file, $contentType, false);
		}
		return null;
	}
582149
protected function _file($id)
    {
        $instance = self::getInstance();
        $fileNmae = $instance->_idToFileName($id);
        return self::cacheDir() . $fileNmae;
    }
1098218
public function getSourceUrlById($id) {
        $image = instance(new Model_Image)->fetchById($id);
        if (!$image) {
            throw new InvalidArgumentException(self::ERROR_IMAGE_NOT_FOUND);
        }
        return $this->getSourceUrl($image['filename']);
    }
728186
public function load($id)
    {
        /** @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $loader **/
        foreach ($this->procedureLoaders as $loader) {

            try {

                $procedure = $loader->load($id);

                return $procedure;

            } catch (\Exception $e) {}

        }

        throw new \InvalidArgumentException(sprintf('No valid procedure loader could be found to load the \'%s\' procedure.', $id));
    }
721976
public function show($id)
    {
        $file = $this->fileRepo->getById($id);
        if (!empty($file)) {
            $this->authorize('read', $file);
            return $this->respondWithSuccess($file, new FileTransformer);
        }
        return $this->respondNotFound();
    }
753934
public function id_to_url($id){
    if ( $file = $this->id_to_real($id) ){
      return $this->real_to_url($file);
    }
    return false;
  }
430739
protected function _file($id)
    {
        $path = $this->_path($id);
        $fileName = $this->_idToFileName($id);
        return $path . $fileName;
    }
131727
public function getDownload4Id($id)
    {
        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->where('p.id = :id')
            ->setParameter('id', $id)
            ->setMaxResults(1)
            ->getQuery();

        return $query->getOneOrNullResult();
    }
1015196
public function importDownload(string $id, string $type = 'original') : Response
    {
        $table = TableRegistry::get('CsvMigrations.Imports');
        $entity = $table->get($id);
        Assert::isInstanceOf($entity, Import::class);

        $path = $entity->get('filename');
        if ('processed' === $type) {
            $path = ImportUtility::getProcessedFile($entity);
        }

        return $this->response->withFile($path, ['download' => true]);
    }
799298
public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
    {
        $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);

        if (! is_null($name)) {
            return $response->setContentDisposition($disposition, $name, $this->fallbackName($name));
        }

        return $response;
    }
539104
public function downloadTorrent($id, $path = '')
	{
		$request  = $this->sendRequest($this->baseUrl."/torrents/download/".$id, null, 0);
		$response = json_decode($request['body'], true);

		if (NULL === $response)
		{
			preg_match('/filename="(.*?)"/i', $request['header'], $filename);

			$file = fopen($path.'/'.$filename[1], 'w+');
			fwrite($file, $request['body']);
			fclose($file);
		} else {
			if (array_key_exists('error', $response))
			{
				if ($response['code'] == 201 || $response['code'] == 202) {
					$this->connect();
					return $this->downloadTorrent($id, $path);
				}
				throw new \Exception('Erreur '.$response['code'].' : '.$response['error']);
			}
		}
	}
364285
public function deleteFileById($id)
    {
        if ($id instanceof \MongoId) {
            $result = $this->getMongoCollection()->delete($id);
        } else {
            try {
                $result = $this->getMongoCollection()->delete(new \MongoId($id));
            } catch (\MongoException $e) {
                $result = $this->getMongoCollection()->delete($id);
            }
        }
        if ($result['ok'] !== (double) 1) {
            throw new Exception('Error deleting file: ' . $result['err'] . ': ' . $result['errmsg']);
        }
        
        return $this;
    }