@ahmed alaa I run a video platform myself. You need to do multi-part uploads. You should also just be uploading directly to S3. There’s no point uploading to your server, just then have your server send the same data from there to S3. You’re adding an extra step (and time) for no reason.
Apr 18, 2024
4
Level 3
What's the best way to upload large files to S3 Buckets
Hello, I'm using Vue js to create chunks for Laravel 11 backend and from there these chunks should be transferred to AWS S3 Buckets. I used an append for each new chunk, it was working but had plodding progress.
// Upload a video to S3
public function uploadVideo(Request $request)
{
// Upload chunks and if is_last is true, combine them
$file = $request->file('chunk');
$isLast = $request->input('is_last');
$file = $request->file('chunk');
Storage::disk('s3')->append('test/videos/rrr/' . $file->getClientOriginalName(), $file->get(), null);
if ($isLast == "true") {
// Change the privacy of the file
$path = 'test/videos/rrr/' . $file->getClientOriginalName();
Storage::disk('s3')->setVisibility($path, 'public');
}
return response()->json([
'status' => 'success',
'message' => 'Chunk uploaded successfully',
]);
}
I tried streaming and it seems that it's working to the end, but when I open the video file it shows a black screen.
// Upload a video to S3
public function uploadVideo(Request $request)
{
$file = $request->file('chunk');
$stream = fopen($file->getRealPath(), 'r');
Storage::disk('s3')->put('test/videos/streams/' . $file->getClientOriginalName(), $stream, 'public');
fclose($stream);
return response()->json([
'status' => 'success',
'message' => 'Chunk uploaded successfully',
]);
}
So what's the problem and the best way to fix it?
Please or to participate in this conversation.