I am using large file upload aws s3 bucket in laravel but i am facing issue “Your proposed upload is smaller than the minimum allowed size” filesize 9.8
public function testS3Link()
{
$link = "http://localhost/instacon-web/public/videoUpload/sample10mb.mp4";
$time = time();
// Destination path on S3 bucket
$s3FilePath = 'instameet/'.$time.".mp4";
// Initialize S3 client
$s3 = new S3Client([
'version' => 'latest',
'region' => 'ap-south-1', // Change this to your desired AWS region
'credentials' => [
'key' => 'AKIAEXAMPLE',
'secret' => 'examplekey',
],
]);
try {
// Get file size using cURL
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$data = curl_exec($ch);
$fileSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
// Determine the part size
$partSize = 5 * 1024 * 1024; // 5 MB
$partNumber = 1;
// If the file size is smaller than the part size, upload it as a single part
if ($fileSize <= $partSize) {
$result = $s3->putObject([
'Bucket' => 'instacon',
'Key' => $s3FilePath,
'Body' => fopen($link, 'rb'),
]);
dd($s3FilePath);
}
// Initiate the multipart upload
$result = $s3->createMultipartUpload([
'Bucket' => 'instacon',
'Key' => $s3FilePath,
]);
// Get the upload ID
$uploadId = $result['UploadId'];
// Upload the parts of the file
$file = fopen($link, 'rb');
while (!feof($file)) {
$part = fread($file, $partSize);
$result = $s3->uploadPart([
'Bucket' => 'instacon',
'Key' => $s3FilePath,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'Body' => $part,
]);
$parts[] = [
'PartNumber' => $partNumber,
'ETag' => $result['ETag'],
];
$partNumber++;
}
fclose($file);
// Complete the multipart upload
$s3->completeMultipartUpload([
'Bucket' => 'instacon',
'Key' => $s3FilePath,
'UploadId' => $uploadId,
'MultipartUpload' => [
'Parts' => $parts,
],
]);
dd($s3FilePath);
} catch (S3Exception $e) {
// Handle exception
echo $e->getMessage();
}
}
the above code i have tried but its not working. Its return error Your proposed upload is smaller than the minimum allowed size. Can you suggest any solution.