I have done several hours of research on this but haven't found anything to fix it.
What I'm trying to do is display and img/pdf
witch is linked to a specific DB entry. The files are stored in the local disk storage/app/mycustomFolder
, to make sure these uploaded files are not reachable from publicly.
After a button click: the ajax fires a post request to a Route, then the controller to fetch the file as a response to the ajax call. However, when I want to display the image on the modal it only displays some blob-like text. Not sure how to move on with this.
The ajax:
$('.docview').on('click',function(){
var id = $(this).data('id');
var src = $(this).data('src');
var form_data = new FormData();
form_data.append('id', id);
form_data.append('src', src);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: '/tes/admin/filter/docview/',
type: "POST",
processData: false,
contentType: false,
data: form_data,
success: function(data){
console.log(data);
$('.docDisplay').html('<img src="' + data + '" />');
},
error: function(e){
console.log(e);
$('.docDisplay').html(e);
}
});
});
The Route:
Route::post('/tes/admin/filter/docview/', 'AdminTravelExpenseController@showdoc')->name('admin.tes.displayDoc');
The Controller function:
public function showdoc(Request $request){
$item = \App\TravelExpense::find($request['id']);
if($request['src'] == 1){
$url = $item->doc_url1;
}
else{
$url = $item->doc_url2;
}
if (!Storage::disk('local')->exists($url)){
abort(404);
}
//dd($response);
return response()->file(storage_path('app'.DIRECTORY_SEPARATOR.($url)));
}
I have checked the logs in laravel but it doesn drop any actual error. and it looks like this, hop you guys can help: result of image displayin browser