Download a PDF from MongoDB using jade - javascript

I'm using Node, along with express, Jade and a MongoDB. So far I'm able to query the database and display the data in a webpage.
In the database I am storing PDFs and I would like to be able to download these from the webpage. I can currently get the pdf data in the form of a string (of random character) and display them on a webpage but I'd like to have a button where the user can download it as a pdf.
To insert the pdf into the db I the below python code to open it and pyMongo to insert it.
file = Binary(open(filePath, "rb").read(), 0)
Thanks in advance.

This has little to do with the technologies you mention, but how you handle data on the client. Essentially you will need to utilise frontend JavaScript, HTML and how the browsers handle those in conjunction with data. A pointer would be here https://stackoverflow.com/a/39515978/3580261

Related

using JS to parse an AWS file represented in a download URL

I am using React and JS to build a web app that relies on the REST API of a private web service. Using the API, I can obtain a url for a CSV file that contains data from a server process. The url can be used to download the CSV results from AWS to the user's desktop. The URL is of the form...
https://[identifier1].s3.amazonaws.com/[path and filename.csv]
?X-Amz-Algorithm=[identifier2]
&X-Amz-Date=20210602T001523Z
&X-Amz-SignedHeaders=host
&X-Amz-Expires=3599
&X-Amz-Credential=[identifier3]
%2Fus-east-1%2Fs3%2Faws4_request
&X-Amz-Signature=[identifier4]
(I inserted line feeds above for readability)
My problem is, I don't want the file saved to my local device, I want to parse it directly and read it into a js structure. For example, I would like to display the data directly in a table.
I could download the file and then have the user upload the saved file into the app, but that is not a great workflow. Is there a straightforward way to use the data directly without saving it as a local file?

Connecting local HTML files to Sharepoint database

I am new to using this stuff. I need to make some sort of a connection from a local html file on my computer to either Sharepoint or an Access database. I want to be able to pull data from the Sharepoint/Access db and display it on my html page. I also would like to use javascript to accept user input and in turn query those databases with that.
I currently have built some simple vba that outputs an HTML file with table data and another HTML file which houses that table with an iframe on the page. This is very limited and does not provide full functionality. Can anyone lead me in the right direction? Is this even possible without those pages being hosted on a server somewhere? I understand I may need to use PHP, but I do not believe I can use that functionality without having these files on a server.
Forgive me if I do not sound like I know what I'm talking about...I don't really :)
Thanks!

Let user upload an image into a database using JavaScript

I looked for this question, but I could not find it. Essentially, I have an html form and I want to let the user upload an image into a web database using JavaScript.
Is there a way to accomplish this?
Yes, use a file input element, or if you're using AJAX use FormData.
As an aside, typically once you get the file to the server, you only store the storage path in the db, the image itself is stored on disk; DB aren't particularly good at storing binary data.

Angular: hide JSON data from user

My Angular application loads JSON files as search material using $http
$http.get('my.json').success(function(data){ ... };
Unfortunately, this method loads the JSON file in to the browser and allows the user to see it's content.
Screenshot from Safari
I'd like to hide that file from the user.
To refine my question. I know that I won't be able to totally hide that data from the user.
A user can easily write a script to scrape the data off my site.
I just don't want to hand those files to the user so easily, to just let them sit there for him to just copy and paste.
Everything you sent to client is anyhow visible by client. There is no way to absolutely hide it from him.
All you can do is .zip or encode data on server and unzip or decode it on client. But even in this case all decoding mechanisms will be available to user and if he wishes and has some skills, he can decode it and access all data you send him.
UPD:
Ok, you want to uglify your data so client couldn't see it simple way.
You need to somehow encode data on server, send it encoded to the client, and decode on client so you could use it.
Checkout lz-string - it's js library that can archive / unarchive json strings, converting them to binary format, so data becomes unreadable. And it's pretty fast (I haven't noticed any delays encoding/decoding 2Mb strings - I use it to compress data and store it in localStorage).
It's as easy as LZString.compress(JSON.stringify(data)) to compress json and JSON.parse(LZString.decompress(data)) to decompress.
Only thing you need in addition - to find a server-side library that uses exactly this format. If you use NodeJS at your server, you can take lz-string itself. Otherwise, quick googling gave me solution for php - I think it's pretty possible to find solutions for other languages..
If you want the user to see only parts of the document, you should filter it on the server.
Create some kind of service/Api-function/etc. which loads the document and pass it the user information via ajax request. Now filter it depending on this user information and return the filtered data.

fetch clipboard data

i need to fetch a Prt Screen Image from the clipboard and save it in the database.
I have never really done the save image in database thing before.
The clipboard lives on the client operating system; unless the user pastes the image into an editor, saves it and uploads it using a form, there's no way you can get that data with HTML and the server side alone.
You can't grab a printscreen of a client by with PHP. PHP is a server side technology and cannot access the client. You'd have to use some kind of client side tech like flash, js or java applet. You might want to retag your question if those are permissible.

Categories