Laravel Vapor - Code Sync from Shipping Portal to use S3 Bucket to replace local storage

This commit is contained in:
Dillon Ngo
2024-05-25 12:12:18 +08:00
parent 9d4ebdf9fe
commit 5da53651d4
@@ -20,14 +20,28 @@ class Convert1688PurchaseOrderToProductList
$productList = [];
$shipping = 0;
$discount = 0;
$text = "";
$filepath = "";
$filesystemDriver = Storage::getDefaultDriver();
$file = $file->file->file_info->original->file;
if($filesystemDriver === 's3'){
$fileContent = Storage::disk('s3')->get($file);
$filepath = storage_path('app/temp.pdf');
file_put_contents($filepath, $fileContent);
}
else{
$filepath = Storage::disk('documents')->path($file);
}
try {
$pdf = $parser->parseFile(Storage::disk('documents')->path($file->file->file_info->original->file));
$pdf = $parser->parseFile($filepath);
$text = $pdf->getText();
} catch (Exception $exception) {
throw new MalformedRequestException('Invalid file format.');
}
$text = $pdf->getText();
if(str_contains($text, '订单详情单')) throw new MalformedRequestException('Can\'t process non english documents');
$tables = explode('Amount (yuan)', $text);