error while uploading video file > 2gb in s3 bucket
below is html code:
<form method="POST" action="{{ route('store') }}" enctype="multipart/form-data">
@csrf
<div class="form-group row">
<div class="col-sm-3">
<label class="control-label">Photo 1 / फोटो 1 <br>No Collage or Edited Photos Only Group
photos Allowed</label>
</div>
<div class="input-group col-sm-9">
<input type="file" class="form-control w-100" name="photo1">
@error('photo1')
<span class="text-danger font-weight-bold">{{ $message }}</span>
@enderror
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">
<label class="control-label">Photo 2 / फोटो 2<br>No Collage or Edited Photos Only Group
photos Allowed</label>
</div>
<div class="input-group col-sm-9">
<input type="file" class="form-control w-100" name="photo2">
@error('photo2')
<span class="text-danger font-weight-bold">{{ $message }}</span>
@enderror
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">
<label class="control-label">Upload Video</label>
</div>
<div class="input-group col-sm-9">
<input type="file" class="form-control w-100" name="video">
@error('video')
<span class="text-danger font-weight-bold">{{ $message }}</span>
@enderror
</div>
</div>
</form>
below is controller side code:
public function store(GeetFormRequest $request)
{
$formDetails = GeetForm::create($request->except(['photo1', 'photo2', 'video']));
// Save photo1 and photo2 immediately
$photo1Path = $request->file('photo1')->store('photos1', 's3');
$photo2Path = $request->file('photo2')->store('photos2', 's3');
$photo1Url = Storage::disk('s3')->temporaryUrl($photo1Path, now()->addMinutes(60));
$photo2Url = Storage::disk('s3')->temporaryUrl($photo2Path, now()->addMinutes(60));
$formDetails->update([
'photo1' => $photo1Url,
'photo2' => $photo2Url,
]);
// Queue video processing if video file exists
if ($request->hasFile('video')) {
$videoFile = $request->file('video');
$chunkCount = ceil($videoFile->getSize() / (10 * 1024 * 1024)); // 10MB chunks
for ($i = 1; $i <= $chunkCount; $i++) {
$chunk = file_get_contents($videoFile->path(), false, null, ($i - 1) * (10 * 1024 * 1024), 10 * 1024 * 1024);
ProcessFileUpload::dispatch($formDetails, $i, $chunk, $chunkCount)->onQueue('video_processing');
}
}
// Return immediate response to the user
return redirect()->back()->with('success', 'Form submitted successfully. Video upload is in progress.');
}
below is dispatch job side code:
class ProcessFileUpload implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
protected $formDetails;
protected $chunk;
protected $partNumber;
protected $totalParts;
/**
* Create a new job instance.
*/
public function __construct(GeetForm $formDetails, $partNumber, $chunk, $totalParts)
{
$this->formDetails = $formDetails;
$this->partNumber = $partNumber;
$this->chunk = $chunk;
$this->totalParts = $totalParts;
}
/**
* Execute the job.
*/
public function handle(): void
{
// Logic to handle the chunked upload to S3
$videoFileName = 'video_' . $this->formDetails->id . '_part_' . $this->partNumber;
$videoPath = 'videos/' . $videoFileName;
Storage::disk('s3')->put($videoPath, $this->chunk);
// If all chunks uploaded, merge them
if ($this->partNumber == $this->totalParts) {
$this->mergeChunks($this->formDetails);
}
}
protected function mergeChunks($formDetails)
{
$videoChunks = [];
// Fetch all uploaded chunks from S3
for ($i = 1; $i <= $this->totalParts; $i++) {
$videoFileName = 'video_' . $formDetails->id . '_part_' . $i;
$videoPath = 'videos/' . $videoFileName;
$videoChunks[] = Storage::disk('s3')->get($videoPath);
Storage::disk('s3')->delete($videoPath);
}
// Concatenate all chunks
$videoContent = implode('', $videoChunks);
// Upload the complete video to S3
$videoPath = 'videos/video_' . $formDetails->id . '.mp4';
Storage::disk('s3')->put($videoPath, $videoContent);
// Update the form details with the video URL
$videoUrl = Storage::disk('s3')->temporaryUrl($videoPath, now()->addMinutes(60));
$formDetails->update([
'video' => $videoUrl,
]);
}
from above all files are saved in s3 bucket , but i want to upload video file as well whose size may be > 1gb or 2gb. how to handle all request as many user upload files whose size may be in Gb or MB. i have provided code for save file in s3 bucket , kindly help out from this issue.
i want to upload that file as well but its processes goes under background and save other data in database.
for example: suppose i have uploaded a 2gb video file , then above code will save other data in database and then make queue process to upload video file in s3 bucket. as above code will also handle the multiple users upload large files at same time using above queue mechanism or should we need multipart the video file using queue and upload all chunks files as one file in s3 bucket.
i want to give response to user that form is submitted successfully and rest of video file upload process should be done in queue background so that user don't need to wait for response for several minutes.
after using above scenario it gives me below error as follows:

Please or to participate in this conversation.