0

I am creating a personal blog using node js and mongo db and implementing the function of writing posts.

I thought that the title and description of the post could be saved in the mongo db in String format, but I am curious about how to save the elements such as the image of the textarea and the font size.

I used tinyMCE as a text editor to write the content and the code is as follows.

<form action="/articles" method = "POST">

            <h4>title</h4>
            <input required type="text" name = "title" / class='form-control'><br>
           
            <h4>description</h4>
            <textarea  name="description" class = 'form-control'></textarea><br>
            <h4>contents</h4>
            <textarea id="mytextarea" name="contents" rows = '10'></textarea>
            <a href="/" class ="btn btn-secondary">취소</a><button type = "submit" class="btn btn-primary">저장</button>
        </form>

And an example of a post is as follows.

enter image description here

I am wondering how can I save the contents of a textarea containing a picture in a db.

  • 1
    Usually, you shouldn't save an image in MongoDB, saving it in file storage of the server and saving the path in MongoDB. – Prathamesh More May 13 '21 at 06:10
  • 1
    I guess the challenge is to extract image from text area. If you do that rest will be easy. If it is an URL of an image you can use a regex to obtain the URL. – Rahul May 13 '21 at 06:24

1 Answers1

1

You can refer to this question here.

However, in terms of scalability I do not recommend uploading pictures to mongoDB. It will take way too much space. What I would do is the following:

  1. Create a bucket on AWS s3 or something similar.
  2. Connect your nodes.js server to the newly created bucket using multer in combination with the aws-sdk. (good example here )
  3. Once uploaded the bucket will create a link to the image.
  4. Save the image link on mongoDB.

This way you only store the link, which makes the project a lot more scalable.

ziroock
  • 11
  • 3
  • Thank you so much for being kind and informed. I don't know if I can do it because I have little knowledge about the web, but I'll try it. –  May 13 '21 at 07:32
  • Let me know if you have any questions, I probably will be able to help a bit :) – ziroock May 16 '21 at 03:11