Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Add fix for big file sizes
Browse files Browse the repository at this point in the history
Closes #750
  • Loading branch information
rijkvanzanten committed Apr 12, 2019
1 parent 0f7235d commit 0fce6a4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/Directus/Database/TableGateway/BaseTableGateway.php
Expand Up @@ -387,6 +387,27 @@ public function addRecordByArray(array $recordData)
$TableGateway->ignoreFilters();
}

// NOTE: This is a dirty fix for https://github.com/directus/api/issues/750
// Currently, the whole file content is being read to a base64 string which is being added
// to the $recordData array. If this data string is too large, the insert() call below this
// if statement will 500 error out without any error logs or anything. I'm assuming it's the
// php process running out of memory. When I removed the data key for every file, I noticed
// that the thumbnailer stopped working. For now, this if statement will check if the record
// contains both a filename and a data key, indicating that it's a file. If the length of the
// data key is over 25 million characters, we stop passing on the data key. As mentioned,
// this data string is base64 encoded, so this 25 million number doesn't translate very well
// into bytes. I believe it's somewhere in the 20~25MB range, which should be plenty for
// photos, which are the only usecase for the thumbnailer.
// TODO: Move this somewhere more sensible, and don't read the whole file contents into memory
// in the first place.
if (
array_key_exists('filename', $recordData) &&
array_key_exists('data', $recordData) &&
strlen($recordData) > 25000000

This comment has been minimized.

Copy link
@cesasol

cesasol May 3, 2019

Contributor

This shouldn't be strlen($recordData['data']) > 25000000 ?

This comment has been minimized.

Copy link
@rijkvanzanten

rijkvanzanten May 3, 2019

Author Member

I think you're right @cesasol. Mind opening a PR?

This comment has been minimized.

Copy link
@benhaynes

benhaynes May 6, 2019

Member

I added a PR for this... did not test though! :)

Thanks @cesasol

) {
$recordData = ['filename' => $recordData['filename']];
}

$TableGateway->insert($recordData);

if (static::$emitter && $listenerId) {
Expand Down

0 comments on commit 0fce6a4

Please sign in to comment.