Laravel Vapor - Fix path to upload documents to S3 bucket with dynamic path

This commit is contained in:
Dillon Ngo
2023-12-28 23:26:53 +08:00
parent aa319fadc9
commit 0f61a84fc5
3 changed files with 33 additions and 22 deletions
@@ -99,15 +99,17 @@ class ConvertsBase64ToFile
*/
private function generateFile(FileObject $file, string $suffix = '') {
// $filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension();
// Storage::disk('documents')->put($filePath, $file->getDecodedData());
// return $filePath;
$filePath = 'localhost/'.$file->getFileName().$suffix.'.'.$file->getExtension();
Storage::put($filePath, $file->getDecodedData(), 's3');
return $filePath;
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver == 's3'){
$filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension();
Storage::put($filePath, $file->getDecodedData(), 's3');
return $filePath;
}
else{
$filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension();
Storage::disk('documents')->put($filePath, $file->getDecodedData());
return $filePath;
}
}
/**