Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,19 @@ public function getPath(string $filename, string $prefix = null): string
*/
public function upload(string $source, string $path, int $chunk = 1, int $chunks = 1, array &$metadata = []): int
{
return $this->uploadData(\file_get_contents($source), $path, \mime_content_type($source), $chunk, $chunks, $metadata);
$handle = fopen($source, 'rb');
if (! $handle) {
throw new \Exception('Failed to open the source file.');
}

$contentType = mime_content_type($source);
$fileSize = filesize($source);
$chunkSize = ceil($fileSize / $chunks);
fseek($handle, ($chunk - 1) * $chunkSize);
$data = fread($handle, $chunkSize);
fclose($handle);

return $this->uploadData($data, $path, $contentType, $chunk, $chunks, $metadata);
}

/**
Expand Down Expand Up @@ -268,14 +280,14 @@ public function uploadData(string $data, string $path, string $contentType, int
/**
* Transfer
*
* @param string $path
* @param string $destination
* @param Device $device
* @return string
* @param string $path
* @param string $destination
* @param Device $device
* @return bool
* @throws Exception
*/
public function transfer(string $path, string $destination, Device $device): bool
{
$response = [];
try {
$response = $this->getInfo($path);
} catch (\Throwable $e) {
Expand Down