Media Storage

Choose local or the cloud to store photos, videos, attachments and audio files; and learn how to setup JReviews for video and audio encoding.

Overview

JReviews provides several options to choose from when it comes to storage and each media type can be setup with a different storage service. The following storage services are available out of the box:

  • Local
  • Amazon S3 - AWS
  • Rackspace Files
  • DigitalOcean Spaces

Video and audio uploads are encoded to optimize them for playback. For videos, a frame is also grabbed during the encoding process to use it as the video image. While it's possible to skip the encoding of mp3 audio files via settings, since this format is compatible with the majority of browsers, the video uploads are always encoded to optimize them for streaming.

For audio and video encoding, JReviews supports:

  • Local with FFMPEG
  • Encoding.com
  • Transloadit.com
  • Zencoder.com

Video encoding is resource intensive and that's why we provide the integration with cloud encoding services. Some of them, like Transloadit, even provide a generous free tier.

The video encoding process is not needed for embedded videos, but these still make use of storage for the images. The following video platforms are supported for embedded videos:

  • YouTube
  • Dailomotion
  • Twitch
  • Vimeo

Storage Settings

You can find the storage settings at Configuration → Media Settings → Storage. By default all media types are set to Local storage.

You can also change the original and thumbnail folder names and these settings apply to all storage options.

Changing the storage service, paths, and folders will not automatically move the existing files. Any existing media files need to be moved manually using an FTP client, or any other tool of your preference.

Local Storage

For local storage you modify the upload path, and also change the folder names for each media type, which by default are set to: photos, videos, attachments and audio.

Cloud Storage

Each cloud storage service has its own settings to be able to interact with their APIs. These include API keys, secret phrases, regions, etc. Make sure you grab the correct values from your provider and paste them in the corredponding settings.

On top of this, you need to add the bucket names for each media type. You can use the same bucket for all media types, but we made it flexible so you can use a different bucket for each media type if that's more your style.

When creating bucket names, use hyphenated names, without dots in them. This allows using the bucket name as the sub-domain of the platform domain which will support SSL connections. Otherwise, depending on the storage service, you may also need to set up a CDN which changes the URL for media and ensures that SSL URLs also work. Keep reading to find out more about using a CDN service.

Amazon S3

All Amazon S3 buckets created before April 2023 work out of the box without requiring any extra steps. However, after this date all buckets are created with public access blocked by default so it's necessary to make a few adjustments to allow files to be uploaded with public access so they can be loaded and displayed on web browsers.

  1. Navigate to the S3 Console:

    • Open the AWS S3 Console.
    • Find your bucket (e.g., your-bucket-name) and click on it.
  2. Disable Block Public Access:

    • Go to the Permissions tab.
    • Under Block public access (bucket settings), click Edit.
    • Uncheck all options to allow public access.
    • Click Save changes.
  3. Set Bucket Policy:

    • In the Permissions tab, scroll down to Bucket policy.
    • Click Edit.
    • Copy and paste the following policy, but replace bucketname with the actual name of your bucket.
    {
      "Version": "2012-10-17",
      "Statement": [
          {
              "Sid": "PublicReadForGetBucketObjects",
              "Effect": "Allow",
              "Principal": "*",
              "Action": "s3:*",
              "Resource": "arn:aws:s3:::bucketname/*"
          }
      ]
    }
    
    • Click Save changes.

Notes:

  • Ensure that your bucket name is correctly replaced in the policy (e.g., arn:aws:s3:::your-bucket-name/*).
  • This setup allows public read access to all objects in your bucket (s3:GetObject), but it does not allow public writing or other actions.

Encoding Services

You can find the encoding settings at Configuration → Media Settings → Storage.

To setup an encoding service, first select the service. For videos, choose the desired encoding output resolution and bitrate. For audio, choose if you want to bypass encoding for mp3 files.

Each encoding service has its own settings to be able to communicate with their API. Get the values from your account on the service website and paste them in the corresponding settings.

Local Encoding with FFMPEG

To be able to encode files on your own server your server needs to have the FFMpeg and FFProbe libraries installed. If you need assistance with this, you need to contact your hosting provider.

Video encoding requires the libx264 and fdk-aac encoders. While audio encoding requires libmp3lame.

CDN Services

With JReviews you are able to use any CDN service to deliver your media files. If you are unfamiliar with CDNs (Content Delivery Networks), you can read CloudFlare's CDN definition.

You can find the settings at Configuration → Media Settings → CDN. There you are able to enable the CDN functionality separately for each media type and enter the corresponding CDN URL. When generating the media URLs, JReviews automatically replaces your site's URL, with the CDN URL.

Setting up a CDN with your chosen storage service is beyond the scope of this article. Please consult with your storage and CDN service providers.

Embed Video APIs

You can find the video embed settings at Configuration → Media Settings → Storage, including the API Key settings for YouTube and Twitch. These platforms require an API Key to be able to read the information about a video.

YouTube Video Embeds

For YouTube videos, JReviews includes a fallback method that works out of the box and uses the oembed.com API, but this API response doesn't include the video duration. If you are ok with that, then there's nothing else to setup.

If you want to use the YouTube API, you need to head over to the Google Console:

  • Create a project if you don't already have one for this site
  • Generate a Server API Key credential that you will copy to JReviews
  • Enable the YouTube Data API

Avoid restricting the server key until after you've tested the video embed in JReviews. To restrict the key, use your server's IP address.

You can also learn more about creating your YouTube credentials and enabling the API in the Google YouTube getting started guide.

Large Media Uploads

When your site requires uploading large media files, there's a few things you need to take into consideration.

Generating thumbnails for large and high resolution images is a memory intensive process. You should adjust the PHP memory_limit setting accordingly to avoid memory errors when generating thumbnails.

Uploading large files can also lead to timeout errors while the server waits for files to finish uploading, especially when using cloud storage because the file is first uploaded to your server, then to the cloud storage provider. For this reason you need to make sure that all timeout related settings have large enough values.

You can find some examples of changes needed below. In most cases you'll need to restart the server after making the changes. Ask your host or server manager to assist you with any necessary changes.

  • For PHP increase the values for max_input_time, default_socket_timeout. If changing these settings is not enough, also consider increasing max_execution_time. For example:

    # max_execution_time=300
    max_input_time=300
    default_socket_timeout=300
    
  • For Nginx set a value for fastcgi_read_timeout in the Nginx virutal host configuration. For example:

    location ~ [^/]\.php(/|$) {
      # ...
      include fastcgi_params;
      fastcgi_read_timeout 300;
      # ...
    }
    
  • If you use Nginx as Proxy for Apache, add these variables to nginx.conf:

    proxy_connect_timeout       300;
    proxy_send_timeout          300;
    proxy_read_timeout          300;
    send_timeout                300;