Skip to content

Commit

Permalink
Added admin route for testing file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Nov 27, 2024
1 parent 78764d6 commit 1e2b80f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Http/Controllers/User/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use App\BusinessLogicLayer\User\UserActionResponses;
use App\BusinessLogicLayer\User\UserManager;
use App\Http\Controllers\Controller;
use App\Utils\FileHandler;
use HttpException;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class AdminController extends Controller {
private $userManager;
Expand Down Expand Up @@ -52,4 +56,20 @@ public function addUserToPlatform(Request $request) {

return back();
}

public function checkUploadPage() {
return view('backoffice.admin.check-upload');
}

public function uploadAdminFile(Request $request) {
$path = FileHandler::uploadAndGetPath($request->file('image'), 'solution_img');
$fileObject = $request->file('image');
$uploadedFile = UploadedFile::createFromBase($fileObject);
$originalFileName = $uploadedFile->getClientOriginalName();
$uniqueId = Str::uuid(); // Generate a unique ID for each file
$path_s3 = Storage::disk('s3')->put('uploads/' . $uniqueId, $uploadedFile);
$uploadedFilePath = Storage::disk('s3')->url($path_s3);

return response()->json(['file_path_internal' => $path, 'file_path_s3' => $uploadedFilePath, 'original_file_name' => $originalFileName]);
}
}
22 changes: 22 additions & 0 deletions resources/views/backoffice/admin/check-upload.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@extends('backoffice.layout')
@section('content-header')
<h1>All Crowd-sourcing Projects</h1>
@endsection

@section('content')
<div class="card card-info">
<div class="card-header">
<h3 class="card-title">Upload Image</h3>
</div>
<div class="card-body">
<form action="{{ route('admin.image.upload') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group py-5">
<label for="image">Choose an image to upload:</label>
<input type="file" class="form-control" id="image" name="image" accept="image/*" required>
</div>
<button type="submit" class="btn btn-primary btn-slim">Upload</button>
</form>
</div>
</div>
@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
Route::middleware(['throttle:api-public'])->group(function () {
Route::group(['prefix' => 'admin'], function () {
Route::get('/phpinfo', fn () => phpinfo());
Route::get('/check-upload', [AdminController::class, 'checkUploadPage']);
Route::post('/upload-files', [AdminController::class, 'uploadAdminFile'])->name('admin.image.upload');
});
});
});
Expand Down

0 comments on commit 1e2b80f

Please sign in to comment.