Laravel
HostArena S3 Storage može se koristiti kao podrazumevani ili dodatni disk za skladištenje fajlova u Laravel aplikacijama. Laravel koristi Flysystem, koji pruža punu podršku za Amazon S3 kompatibilne servise.
Šta je potrebno?
Pripremite sledeće podatke iz korisničkog panela:
-
Endpoint
-
Access Key
-
Secret Key
-
Naziv Bucket-a
Primer:
| Polje | Primer |
|---|---|
| Endpoint | https://username.s3.hostarena.rs |
| Bucket | username |
| Access Key | Dostupan u panelu |
| Secret Key | Dostupan u panelu |
Instalacija
Instalirajte AWS S3 adapter:
composer require league/flysystem-aws-s3-v3
Podešavanje .env
Dodajte ili izmenite sledeće vrednosti:
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY
AWS_BUCKET=username
AWS_ENDPOINT=https://username.s3.hostarena.rs
AWS_USE_PATH_STYLE_ENDPOINT=false
Podešavanje config/filesystems.php
Disk s3 treba da koristi vrednosti iz .env fajla.
Laravel će automatski koristiti navedeni Endpoint, Access Key, Secret Key i Bucket.
Test upload
Primer čuvanja fajla:
Storage::disk('s3')->put('test.txt', 'HostArena S3 Storage');
Provera fajla
Storage::disk('s3')->exists('test.txt');
Preuzimanje fajla
Storage::disk('s3')->get('test.txt');
Brisanje fajla
Storage::disk('s3')->delete('test.txt');
Upload korisničkog fajla
Storage::disk('s3')->putFile('uploads', $request->file('file'));
Generisanje URL-a
Storage::disk('s3')->url('image.jpg');
Najčešći problemi
Access Denied
Proverite Access Key i Secret Key.
Bucket does not exist
Proverite naziv Bucket-a.
Unable to connect
Proverite Endpoint:
https://username.s3.hostarena.rs
SSL greška
Proverite da li koristite HTTPS i validan SSL sertifikat.
