Skip to content
Merged
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
17 changes: 13 additions & 4 deletions src/Mixins/MixinUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Nutgram\Laravel\Mixins;

use Illuminate\Http\File as LaravelFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Psr\Container\ContainerExceptionInterface;
Expand Down Expand Up @@ -42,13 +41,23 @@ public static function saveFileToDisk(File $file, string $path, ?string $disk =
}

//create temp file
$tmpFile = tempnam(sys_get_temp_dir(), uniqid(time(), true));
$maxMemory = 20 * 1024 * 1024;
$tmpFile = fopen(sprintf("php://temp/maxmemory:%d", $maxMemory), 'wb+');

//download file to temp file
$http = $bot->getContainer()->get(ClientInterface::class);
$http->get($bot->downloadUrl($file), array_merge(['sink' => $tmpFile], $clientOpt));
$response = $http->get($bot->downloadUrl($file), array_merge(['sink' => $tmpFile], $clientOpt));

//detach resource
$response->getBody()->detach();

//save temp file to disk
return $storage->putFileAs('/', new LaravelFile($tmpFile), $path);
$result = $storage->put($path, $tmpFile);

//close temp file
fclose($tmpFile);

//return result
return $result;
}
}