where you are storing your images on server. can you give path ?
How to return the url of an image file in laravel ?
Friends, I am using Angular 6 for front-end and laravel 5.5.44 as backend. In my code I can download a file using the code
public function downloadDocs($regid, $type, $filename) {
Log::debug("inside FileDownloadController->downloadDocs ".$filename);
$loadPath = env('APP_UPLOADS_DIR') . DIRECTORY_SEPARATOR;
switch ($type) {
case 'R':
case 'A':
$loadPath .= env('SYSGENRTD_SAVE_DIR');
break;
case 'U':
$loadPath .= env('FLATTACHMNT_SAVE_DIR');
break;
case 'C':
$loadPath .= env('CERT_SAVE_DIR');
break;
case 'default':
break;
}
$loadPath .= DIRECTORY_SEPARATOR . $filename;
return response()->download($loadPath);
}
by giving URL : http://localhost:8000/api/civilregn/v1/downloadDoc/1/U/Original.jpg
But I need to show the same image on my front-end as < img [src]=? >
I don't know How to return the URL of the file to front end in format of http://localhost:8000/
I wrote a function with code
public function viewDocs($regid, $type, $filename) {
Log::debug("inside FileDownloadController->viewDocs ".$filename);
$loadPath = env('APP_UPLOADS_DIR') . DIRECTORY_SEPARATOR;
switch ($type) {
case 'R':
case 'A':
$loadPath .= env('SYSGENRTD_SAVE_DIR');
break;
case 'U':
$loadPath .= env('FLATTACHMNT_SAVE_DIR');
break;
case 'C':
$loadPath .= env('CERT_SAVE_DIR');
break;
case 'default':
break;
}
$loadPath .= DIRECTORY_SEPARATOR . $filename;
//die(response()->view($loadPath));
return response()->view($loadPath);
}
try to access the file using URL: http://localhost:8000/api/civilregn/v1/viewDoc/1/U/Original.jpg
but got error as
InvalidArgumentException View [.var.www.html.ERP_new.Uploads.attachments.Original.jpg] not found.
My .env configuration for file path is
APP_URL=http://localhost
APP_UPLOADS_URL=http://localhost/Uploads
APP_DIR=/var/www/html/ERP_new/ERP_Project
APP_FILE_SERVER=127.0.0.1
APP_UPLOADS_DIR=/var/www/html/ERP_new/Uploads
ANNEXURES_DIR=/var/www/html/ERP_new/ERP_Annexures/AnnexureTemplates
#CR DIRECTORIES
SYSGENRTD_SAVE_DIR=annexures_pdf
FLATTACHMNT_SAVE_DIR=attachments
CERT_SAVE_DIR=certificate_pdf
CR_ANNEXTEMP_DIR=CivilRegistration
please advise How I can take href src for file to show on front-end..
Thanks
Anes
Please or to participate in this conversation.