How to store files in MongoDB using Node Js and AngularJs? - angularjs

I am weak in coding so I am asking this type of question. I've read similar questions but could not find out the solution to my question.
All I want is to store the actual word or pdf file (and not links) in the MongoDB using NodeJs as backend and AngularJs as frontend.
I've read that GridFS is used for this but I could not figure out how!

Ok... Firstly you cannot save a file in MONGODB, only text. Thus what I do is save the path to the file. For example: src: "/uploads/pdfs/pdf1.pdf". Save the file in node JS using https://github.com/jacoborus/node-filesaver . Slim example of what I would do: http://pastebin.com/huvCknWb

Related

Save and get media from MongoDB database

I have a MERN Stack in which the user upload one of the 4 types of files: .pdf, .jpeg, .psd, .ai and I used FileReader to save it as buffer to mongoDB Database. I want to render it back to my React app (automatically download the file) on click. 'react-pdf' didnt help because the data which comes back from the database is buffer type and hence it shows 'Failed to load PDF' How do I solve this issue for all file types?
What I think there is nothing wrong with your client-side part the main cause of this is how you are storing it into DB
To store files in MongoDB you should try to use GridFS
You can find some tutorials about working with GridFS (example).
Check your MongoDB Driver's API and try to implement it in your project

How can I store a img into a MongoDB?

I need to make a "gallery" like Google Photos for a class project. My idea consists in a web app that allows a user to upload a file (image) and save it to a db and after that to show it in the web app. I just want to know how should the structure of my collection be if that collection saves a file (<16MB I read for >16MB we have to use gridfs).
For the back-end, I will use Node (with Express, Mongoose ... and so on) and for the front-end I will use react or vue.js. I am not sure yet.
Any suggestion is accepted.
You can do the following two things.
Upload image to s3 and save its link in the mongoDB. More Read(https://medium.com/#fabianopb/upload-files-with-node-and-react-to-aws-s3-in-3-steps-fdaa8581f2bd).
Save image in database in a GridFS collection. More Read
(https://docs.mongodb.com/manual/core/gridfs/#when-to-use-gridfs)

Where to store resource files with Angular

I've got a JSON file containing a list of time zones which I want to reference in my project, but I'm not sure of where I should store this.
I'm considering making a directory called /resources or /assets
Alternatively, I could store in /src/services, as this is kind of the data layer of my app. The one problem with this though is that this file is a JSON file and not actually a service...
Any opinions on where to store this kind of thing?
John Papa's guide is the best when it comes to code structuring: Please refer to this url: https://johnpapa.net/angular-app-structuring-guidelines/
It talks about where you should put certain files and components in your Angular project.

Upload file using Angular JS

I need to save a PDF file which the user uploads to database as a byte array (in Angular JS). I have tried using the file upload module provided by Angular. It doesnt seem to work for me.I have also tried posting the PDF file through a $http post call of jquery. This method works if I accept the data at the server side as a dynamic object of Newtonsoft. However I need a byte array and I am unable to convert this object to a byte array.
This questions is not really about angular but instead it is, based on your description, about how to upload a file using WebApi.
I would recommend your start trying to upload your file using this exmaple:
http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx
When it is ready then adapting it to your angular app.
I had a similar issue a while back. Have a look at this Stack Overflow link.
Uploading/Downloading Byte Arrays with AngularJS and ASP.NET Web API
If you still have some questions, let me know.
I am sending and receiving a lot of byte array data between my clients and servers using Web API. The approach I use is compatible with iPhones, iPad, Android devices, Macs, and Windows PCs/laptops. I haven't checked it on Windows phones yet, but do not expect any problems.
Regards....

capture and save string to local file

I have a very simple app with which I want to capture a string and save it to a file within the app directory. Is it possible to use $http to post/put to a file within the app tree similar to how you'd get static files like views?
Thanks
C
Use HTML5 filesystem API. Example here.

Resources