Skip to content

Commit

Permalink
fetch image- adjust face verification api
Browse files Browse the repository at this point in the history
  • Loading branch information
haidyelnahass committed Mar 1, 2022
1 parent 65c0d70 commit 1f9e146
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/Http/Controllers/ImageUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public function imageUploadPost(Request $request)
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);

$imageName = time() . '.' . $request->image->extension();
// $imageName = time() . '.' . $request->image->extension();

$path = Storage::disk('s3')->put('uploads', $request->image);
$path = Storage::disk('s3')->url($path);

return response()->json(['message' => 'success ,You have successfully upload image.', 'image' => $imageName]);
$imageName = substr($path, -44);

return response()->json(['message' => 'Success! You have successfully uploaded the image.', 'image' => $imageName]);
}
}
9 changes: 9 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;

class UserController extends Controller
{
Expand Down Expand Up @@ -349,4 +351,11 @@ public function verifyEmail(Request $request)
return response()->json(['message' => 'Account verified!'], 200);
}
}

public function getImage() {

$image2 = Storage::disk('s3')->get('uploads/AOGRQGLjcMhNCOZGiWs0faJRfsxCrcteVfWUwrfE.jpg');
// image malformed issue
return base64_encode($image2);
}
}
11 changes: 9 additions & 2 deletions app/Http/Controllers/faceVerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;

class faceVerificationController extends Controller
Expand Down Expand Up @@ -52,7 +53,6 @@ public function faceVerification(Request $request)
}
$rules = [
'image1' => 'required',
'image2' => 'required',
'examId' => 'required',
];

Expand All @@ -69,12 +69,19 @@ public function faceVerification(Request $request)
if ($validator->fails()) {
return response()->json(['message' => 'No image added!'], 400);
}
$imagePath = auth()->user()->image;

$image2 = Storage::disk('s3')->get('uploads/'.$imagePath);
$image2Enc = base64_encode($image2);

$image2Encoded = 'data:image/jpeg;base64,'.$image2Enc;



$response = Http::post('http://3.142.238.250:5000/verify', [
'img' => [[
'img1' => $request->image1,
'img2' => $request->image2,
'img2' => $image2Encoded,
]]
]);

Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
Route::group(['middleware' => ['auth:sanctum']], function () {
Route::post('/auth/logout', [UserController::class, 'logout']);
Route::put('/auth/changePassword', [UserController::class, 'changePassword']);
Route::get('/image', 'App\Http\Controllers\UserController@getImage');
});


Expand Down
2 changes: 1 addition & 1 deletion storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@
"components": {
"schemas": {
"ChangePasswordRequest": {
"title": "changePasswordRequest",
"title": "ChangePasswordRequest",
"description": "change password request body data",
"required": [
"currentPassword",
Expand Down

0 comments on commit 1f9e146

Please sign in to comment.