Opening a PDF file in another window with VueJS laravel using href I want to create href link whenever a user click it it should show the pdf file in separate window. I have tried the below code but id did not work.
getfile(file) { return "uploads/" + file; }
<tr v-for="DocumentType in DocumentTypes.data"v-bind:key="DocumentType.id">
<td><a :href="getfile(DocumentType.file)">{{DocumentType.file}}</a> </td></tr>
if more details are required I will provide
there is no error in console.
any kind of help will be highly appreciated
To open a link in a new tab:
<a href="#" @click.prevent="getfile(DocumentType.file)">{{ DocumentType.file }}</a>
getFile(file) {
window.open("uploads/" + file, "_blank");
}
there is no controller
and the href and function you advised, when I click on it it does not show any
url
Can you provide more code?
What code do you want? I have provided enough for this function
I think you should have a fully qualified url in the window.open(), something like:
window.open("https://yourdomain.com/uploads/" + file], "_blank");
You should use the Storage facade to store the file:
// ...
$upload_path = public_path('uploads');
$file = $request->file('file'); // name of the input file in the form
$filename = time() . '.' . $file->getClientOriginalExtension();
$path = 'uploads'
Storage::put(
public_path('uploads') .'/'.$filename,
file_get_contents($file->getRealPath())
);
// ...
And to retrieve it:
public function show(Request $request)
{
// check . . .
return response()->file(storage_path('uploads/yourFile' ));
}
I found the solution using my provided code but if you click the URL which is consist of an image it opens it in another page but if it is pdf file it does not open it it just download it but I want to view the pdf file too
Use the provided Laravel methods:
return response()->file("path/to/file.pdf"); // to preview the PDF
return response()->download"path/to/file.pdf"); // to download the PDF
Mr.Amuary I am using function not route
Please sign in or create an account to participate in this conversation.