This commit is contained in:
Ubuntu 2023-10-25 20:27:56 +00:00
commit 795fc168c9
3 changed files with 6 additions and 14 deletions

View File

@ -16,7 +16,6 @@ use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Storage;
// use Maatwebsite\Excel\Excel as ExcelType;
use Maatwebsite\Excel\Facades\Excel;
class UserController extends Controller
@ -143,21 +142,11 @@ class UserController extends Controller
$disk = 'imports';
$filename = $file_users->store(path: "", options: $disk);
// $mimeType = $file_users->getMimeType();
// $type = match($mimeType) {
// "text/csv" => ExcelType::CSV,
// "application/vnd.oasis.opendocument.spreadsheet" => ExcelType::ODS,
// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => ExcelType::XLSX,
// "application/vnd.ms-excel" => ExcelType::XLS,
// default => ExcelType::XLSX,
// };
Excel::import(
import: new UsersWithSmartUsersImport($file_logos),
filePath: $filename,
disk: $disk,
// readerType: $type
);
return response()
@ -166,7 +155,7 @@ class UserController extends Controller
} catch (\Throwable $th) {
throw $th;
} finally {
Storage::disk($driver)->delete($filename);
Storage::disk($disk)->delete($filename);
}
}
}

View File

@ -4,12 +4,14 @@ namespace App\Imports;
use App\Models\DadosCadastrais;
use App\Models\User;
use Illuminate\Http\File;
use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Concerns\ToCollection;
use ZanySoft\Zip\Facades\Zip;
@ -113,11 +115,12 @@ class UsersWithSmartUsersImport implements ToCollection
$picture = new File($temp_file_path);
$pathS3 = "avatars/{$picture->hashName()}";
Storage::disk('s3')->missing($pathS3) &&
Storage::disk('s3')->put($pathS3, $picture->getContent());
$filename = \preg_replace("/\.[^\.]+$/", "", $filename);
$this->files_paths[$filename] = url('/images/test.png') ?? Storage::disk('s3')->url($pathS3);
$this->files_paths[$filename] = Storage::disk('s3')->url($pathS3);
\unlink($temp_file_path);
});

View File

@ -74,7 +74,7 @@
"@php artisan config:clear --ansi",
"@php artisan schedule:clear-cache --ansi"
],
"authorized-files": "sudo chown -R www-data:www-data storage/ storage/framework/cache storage/framework/cache/data bootstrap/cache/ public/",
"authorized-files": "sudo chown -R www-data:www-data storage/ bootstrap/cache/ public/ && sudo chown -R :www-data storage/",
"dev": "@php artisan serve --host=0.0.0.0 --port=8080 --ansi"
},
"extra": {