@Route(
"/download/{token}/{path}",
name="youwe_file_manager_download",
requirements={"path"=".+"},
options={"expose":true}
)

@param Request $request
@param string  $path the path of the file that is downloaded
@return Response
183780
public function DownloadAction(Request $request, $path)
    {
        /** @var FileManagerService $service */
        $service = $this->get('youwe.file_manager.service');
        $service->checkToken($request->get('token'));

        /** @var FileManagerDriver $driver */
        $driver = $this->get('youwe.file_manager.driver');
        $parameters = $this->container->getParameter('youwe_file_manager');
        $fileManager = $service->createFileManager($parameters, $driver);

        $filepath = $fileManager->getPath($path, null, true);
        $content = file_get_contents($filepath);
        $filename = basename($path);
        $response = new Response();

        $response->headers->set('Content-Type', 'mime/type');
        $response->headers->set('Content-Disposition', 'attachment;filename="' . $filename . '"');
        $response->setContent($content);

        return $response;
    }
487435
public function localPathAction(Request $request)
    {
        $response = $this->getCacheTimeKeeper()->getResponse();
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        $form = $this->createForm(
            new ChoiceLocalPath(),
            ['path' => $request->get('path') ?: '']
        );

        return $this->render('AnimeDbAppBundle:Form:local_path.html.twig', [
            'form' => $form->createView(),
        ], $response);
    }
270113
public function dropsDownloadAction(Request $request)
    {
        $drops = $this->decodeIdsString($request, Drop::class);
        $dropzone = $drops[0]->getDropzone();
        $this->checkPermission('EDIT', $dropzone->getResourceNode(), [], true);
        $fileName = $dropzone->getResourceNode()->getName();

        $archive = $this->manager->generateArchiveForDrops($drops);

        $response = new StreamedResponse();
        $response->setCallBack(
            function () use ($archive) {
                readfile($archive);
            }
        );
        $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition', 'attachment; filename='.urlencode($fileName.'.zip'));
        $response->headers->set('Content-Type', 'application/zip; charset=utf-8');
        $response->headers->set('Connection', 'close');

        return $response->send();
    }
323836
public function download(Request $request, ResponseFactory $response): BinaryFileResponse
    {
        $data = $this->validate($request, [
            'path'     => 'required',
            'filename' => 'required',
        ]);

        return $response->download(
            $data['path'],
            $data['filename']
        )->deleteFileAfterSend($shouldDelete = true);
    }
1081449
private function getDownloadUrlForFile($path)
    {
        $metadataRaw = $this->getMetadata($path)->getBody()->getContents();
        $metadata = json_decode($metadataRaw);

        return $metadata->{'@content.downloadUrl'};
    }
520243
public function download($request, $match)
    {
        // GET data
        if (array_key_exists('modelId', $match)) {
            $content = Pluf_Shortcuts_GetObjectOr404('CMS_Content', $match['modelId']);
        } else {
            $content = CMS_Shortcuts_GetNamedContentOr404($match['name']);
        }
        // Do
        $content->downloads += 1;
        $content->update();
        $response = new Pluf_HTTP_Response_File($content->getAbsloutPath(), $content->mime_type);
        $response->headers['Content-Disposition'] = sprintf('attachment; filename="%s"', $content->file_name);
        return $response;
    }
851333
public function download($path)
    {
        //Path cannot be null
        if (is_null($path)) {
            throw new Exceptions\BoxClientException("Path cannot be null.");
        }

        //Download File
        $response = $this->postToContent('/files/download', ['path' => $path]);

        //Get file metadata from response headers
        $metadata = $this->getMetadataFromResponseHeaders($response);

        //File Contents
        $contents = $response->getBody();

        //Make and return a File model
        return new File($metadata, $contents);
    }
103223
public function handleAction(FileManager $fileManager, Request $request, $action)
    {
        $response = new Response();
        try{
            $dir = $this->getFilePath($fileManager);
            $fileManager->setDir($dir);
            $fileManager->checkPath();
            if($request->getMethod() === 'POST') {
                $this->checkToken($request->get('token'));
            }
            switch($action){
                case FileManager::FILE_DELETE:
                    $fileManager->deleteFile();
                    break;
                case FileManager::FILE_MOVE:
                    $fileManager->moveFile();
                    break;
                case FileManager::FILE_EXTRACT:
                    $fileManager->extractZip();
                    break;
                case FileManager::FILE_RENAME:
                    $fileManager->renameFile();
                    break;
                case FileManager::FILE_NEW_DIR:
                    $fileManager->newDirectory();
                    break;
                case FileManager::FILE_COPY:
                case FileManager::FILE_CUT:
                    $this->copyFile($action);
                    break;
                case FileManager::FILE_PASTE:
                    $this->pasteFile();
                    break;
                case FileManager::FILE_INFO:
                    $response = new JsonResponse();
                    $response->setData(json_encode($fileManager->getCurrentFile()->toArray()));
                    break;
            }
        } catch(\Exception $e){
            $response->setContent($e->getMessage());
            $response->setStatusCode($e->getCode() == null ? 500 : $e->getCode());
        }
        return $response;
    }
289937
public function getAction(Request $request, $reference, $path)
    {
        $path = '/' . $path;
        // TODO add ß, ä, ö, perhaps other special chars
        $path = urldecode(
            str_replace(array('u%CC_', 'a%CC_', 'o%CC_', '%C3_'), array('ü', 'ä', 'ö', 'ß'), urlencode($path))
        );

        $session = $this->getSessionByHash($reference);
        $file = $session->getFile($path);

        if ($request->get('content') !== null) {
            return $this->getContent($file);
        }

        return $this->handleView($this->view(new File($file, $file->getName(), $reference)));
    }
464676
public function downloadAction()
    {
        $filename = $this->getRequest()->getParam('form');
        $filename = basename($filename);    //Strip paths

        $file = $this->formDir . $filename;

        if (!empty($filename) && file_exists($file)) {
            $this->getHelper('layout')->disableLayout();
            $this->getResponse()->setHeader('Content-Type', 'application/xml; charset=utf-8');
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $filename . '"');
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
            exit;
        } else {
            $this->getResponse()->setHttpResponseCode(404);
            $this->html->div("form $filename not found");
        }
    }
914872
public function streamFile($container, $path, $download = false)
    {
        $file = static::addContainerToName($container, $path);

        if (!is_file($file)) {
            throw new NotFoundException("The specified file '" . $path . "' was not found in storage.");
        }
        $chunk = \Config::get('df.file_chunk_size');
        FileUtilities::sendFile($file, $download, $chunk);
    }
909880
public function downloadMainToken($token)
    {
        $downloadableUrl = $this->downRepository->findByToken($token);
        $path = storage_path("app/public" . DIRECTORY_SEPARATOR. $downloadableUrl->main_path);

        return response()->download($path);
    }
711742
public function toResponse($request)
    {
        $downloadHeaders = [
            'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
            'Content-Type' => $this->mime_type,
            'Content-Length' => $this->size,
            'Content-Disposition' => 'attachment; filename="'.$this->file_name.'"',
            'Pragma' => 'public',
        ];

        return response()->stream(function () {
            $stream = $this->stream();

            fpassthru($stream);

            if (is_resource($stream)) {
                fclose($stream);
            }
        }, 200, $downloadHeaders);
    }
994214
public function createRequest(Request $request, $path)
    {
        $newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all());

        static $setSession;

        if (null === $setSession) {
            $setSession = \Closure::bind(function ($newRequest, $request) { $newRequest->session = $request->session; }, null, Request::class);
        }
        $setSession($newRequest, $request);

        if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
            $newRequest->attributes->set(Security::AUTHENTICATION_ERROR, $request->attributes->get(Security::AUTHENTICATION_ERROR));
        }
        if ($request->attributes->has(Security::ACCESS_DENIED_ERROR)) {
            $newRequest->attributes->set(Security::ACCESS_DENIED_ERROR, $request->attributes->get(Security::ACCESS_DENIED_ERROR));
        }
        if ($request->attributes->has(Security::LAST_USERNAME)) {
            $newRequest->attributes->set(Security::LAST_USERNAME, $request->attributes->get(Security::LAST_USERNAME));
        }

        if ($request->get('_format')) {
            $newRequest->attributes->set('_format', $request->get('_format'));
        }
        if ($request->getDefaultLocale() !== $request->getLocale()) {
            $newRequest->setLocale($request->getLocale());
        }

        return $newRequest;
    }
1029653
public function medialinkAction(Request $request)
    {
        $fileId = $request->get('file_id');
        $router = $this->get('router');

        $urls = [
            'download' => $router->generate('frontendmedia_download', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_URL),
            'inline' => $router->generate('frontendmedia_inline', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_URL),
            'icon' => $router->generate('frontendmedia_icon', ['fileId' => $fileId, 'size' => 16], UrlGeneratorInterface::ABSOLUTE_URL),
        ];

        return new JsonResponse($urls);
    }
1025810
public function downloadAction(string $path): Response
    {
        if (!$meta = $this->filesystem->getMetadata($path)) {
            throw new NotFoundHttpException('Media not found: ' . $path);
        }

        $content = $this->filesystem->read($path);

        $response = new Response($content);
        $response->headers->set('Content-Type', $meta['mimetype']);
        $response->headers->set('Content-Length', $meta['size']);
        $response->headers->set('Content-Transfer-Encoding', 'binary');

        $name = explode('/', $path);

        $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $name[count($name) - 1]);
        $response->headers->set('Content-Disposition', $disposition);

        return $response;
    }
241358
def download(url, path)
      if url.match(FILE_URL)
        FileUtils.cp(url.sub(FILE_URL, ''), path)
      else
        File.open(path, 'w+') do |file|
          Net::HTTP.get_response(URI(url)) do |response|
            response.read_body do |chunk|
              file.write chunk
            end
          end
        end
      end
      path
    end