Copying Large Media Files Fails

One of my clients wants to self-host some video recordings. Naturally I’ve implemented a custom block and use the HTML5 video tag to display it.

The issue I’ve seen happening multiple times now, is that while creating the video file copy in the /media/ directory, the copy process is somehow interrupted/canceled and thus one ends up with a corrupt and incomplete video file. Which of course, since that is being linked on the site, fails to work properly.

I had this happen with 700MB video and with a 1.2GB video and the final file size in the media directory was around 560MB.

Is Kirby doing an actual file copy or is it loading it into memory (which may or may not be capped at 500MB)?

Is there a simple way to disable media file creations for e.g. video files and instead serve the file directly? Given that moving the page and otherwise changing stuff, can lead to duplications within the media directory, so you can quickly assemble multiple GB of data for the same video.

Steps to Reproduce

  • Get an account on some cheap shared hoster
  • Create a new page in the Kirby panel
  • Upload a large (> 500MB) video file (either through FTP or the panel)

Actual Behavior

The file is incomplete and the video is corrupted

Expected Behavior

The copy in the media/ directory is completed and the file is not corrupt

The file is just copied (under the hood using PHP’s copy function), when the URL of the resource is called. The problem is probably that cheap shared hosting is not the best choice when dealing with large files, or that php.ini settings are not correct.

If you’d rather use the original file, create a custom file::url component.

If you want to report an issue, the right place to do so would be on GitHub.

Do you have some pointers into the code where the copying is happening? I’m not very familiar with Kirby’s code base, but would be interested in looking at it more closely.

The copy method in the F::class in the toolkit is the last step in a row of actions, starting with the publish() method in FileActions.php

1 Like