Thursday, 16 March 2017

Upload and retrieve text/pdf/img files on mongodb using mongoose in a MEAN stack application

I've been trying to write a piece of code in which the user creates a dynamic url, uploads a file by clicking on a button on the page, and the user can also download the same file in the same format when he/she visits the same url again. The concept is very much like cl1p with a difference of file in place of text.

I worked out a lot of answers on SO but I cannot find any help on how to accept the file in angular controller, and pass to the back end(node.js code), where the file can be saved on mongodb database using mongoose, and the same file can be retrieved from the mongodb database. Also, I wish to save the complete file in database, not just the path/destination of file.

Please help.

As of now, all I have is -

<div ng-controller="main">
<input type="file" name="myFile" id="file" />
<button type="submit">Upload</button>
</div>

PS: Do not ask me to use GridFS, it is useful in cases when data exceeds 16MB, my file size won't exceed 2~3MB.



via Ritik Saxena

No comments:

Post a Comment