disableUrlUploadFeature example

$fileName,
            (string) mime_content_type($fileName),
            $extension,
            $bytesWritten,
            hash_file('md5', $fileName) ?: null
        );
    }

    public function fetchFileFromURL(Request $request, string $fileName): MediaFile
    {
        if (!$this->enableUrlUploadFeature) {
            throw MediaException::disableUrlUploadFeature();
        }

        $url = $this->getUrlFromRequest($request);

        if ($this->enableUrlValidation && !$this->fileUrlValidator->isValid($url)) {
            throw MediaException::illegalUrl($url);
        }

        $extension = $this->getExtensionFromRequest($request);

        $inputStream = $this->openSourceFromUrl($url);
        
$exception = MediaException::illegalUrl($url);

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_ILLEGAL_URL, $exception->getErrorCode());
        static::assertEquals('Provided URL "http://illegal-url" is not allowed.', $exception->getMessage());
        static::assertEquals(['url' => $url]$exception->getParameters());
    }

    public function testDisableUrlUploadFeature(): void
    {
        $exception = MediaException::disableUrlUploadFeature();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
        static::assertEquals(MediaException::MEDIA_DISABLE_URL_UPLOAD_FEATURE, $exception->getErrorCode());
        static::assertEquals('The feature to upload a media via URL is disabled.', $exception->getMessage());
    }

    public function testCannotOpenSourceStreamToRead(): void
    {
        $url = 'http://invalid-url';

        $exception = MediaException::cannotOpenSourceStreamToRead($url);

        
Home | Imprint | This part of the site doesn't use cookies.