Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "text/vtt" mime type for WebVTT files #5052

Closed
michaelhue opened this issue Oct 5, 2019 · 4 comments

Comments

@michaelhue
Copy link

commented Oct 5, 2019

Description

Some browsers won't load WebVTT (.vtt) files (used in <track> elements) if the mime type is incorrect. Currently WebVTT files are served with text/plain, the correct type is text/vtt.

Please add the following line to src/config/mimeTypes.php:

$mimeTypes['vtt'] = 'text/vtt';

Thank you!

Additional info

  • Craft version: 3.3.7
@michaelhue michaelhue changed the title Add `text/vtt` mime type for WebVTT files Add "text/vtt" mime type for WebVTT files Oct 5, 2019
@michaelhue

This comment has been minimized.

Copy link
Author

commented Oct 5, 2019

Just noticed that doesn't solve the problem I'm having.

I thought that updating src/config/mimeTypes.php will also change the Content-Type of files uploaded to S3 via Craft. But it seems that Flysystem is responsible for setting the Content-Type and is also missing the text/vtt type. Will investigate further.

brandonkelly added a commit that referenced this issue Oct 8, 2019
@brandonkelly

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

Just added it anyway.

@andris-sevcenko Can you look into whether it’s feasible to override Flysystem’s mime types?

@michaelhue

This comment has been minimized.

Copy link
Author

commented Oct 9, 2019

Thanks @brandonkelly! This is my custom S3 adapter solution for now. A bit hacky, but it seems to work.

<?php

use craft\helpers\FileHelper;
use League\Flysystem\Config;
use League\Flysystem\AwsS3v3\AwsS3Adapter as BaseAdapter;
use League\Flysystem\Util;

class AwsS3Adapter extends BaseAdapter
{
	protected function upload($path, $body, Config $config)
	{
		try {
			$types = '@config/mimeTypes.php';

			$leagueType = Util::guessMimeType($path, $body);
			$craftType = FileHelper::getMimeTypeByExtension($path, $types);

			$mime = $leagueType != 'text/plain' ? $leagueType : $craftType;

			$config->set('mimetype', $mime);
		} catch (\Exception $err) {
			// ignore errors for now...
		}

		// Continue with original upload method.
		return parent::upload($path, $body, $config);
	}
}
@brandonkelly

This comment has been minimized.

Copy link
Member

commented Oct 11, 2019

Thanks @andris-sevcenko!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.