I am using Laravel 9 to upload files to DigitalOcean Spaces. The upload works perfectly on my local machine for both small and large files. However, after deploying to a server, it only works for small files—large files fail to upload.
Here’s my Laravel upload code:
$disk = Storage::disk('spaces');
$directory = 'media_transcription/audio/';
$fileName = uniqid() . '_' . $audioFile->getClientOriginalName();
$filePath = $directory . $fileName;
try {
$uploaded = $disk->put($filePath, file_get_contents($audioFile), 'public');
if ($uploaded) {
if ($disk->exists($filePath)) {
Log::info(' File exists in storage!', ['file_path' => $filePath]);
} else {
return response()->json(['error' => 'File upload verification failed.'], 500);
}
} else {
return response()->json(['error' => 'File upload failed.'], 500);
}
} catch (\Exception $e) {
Log::error('Failed to upload file to DigitalOcean Spaces.', ['error' => $e->getMessage()]);
return response()->json(['error' => 'File upload failed.'], 500);
}