0

Do I have to write a code in the backend/controller for a trix-editor so that I can attach and upload files w/ it? Or it's just purely frontend stuff like in the script part of the application ?

TheBAST
  • 2,280
  • 7
  • 26
  • 53
  • If you want to in any way store what is uploaded, you need a place to send that file to - generally a backend. – Trent Dec 13 '19 at 02:05
  • @Trent Some WYSIWYG editors inline uploaded files using [data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs). – ceejayoz Dec 13 '19 at 02:22
  • But if you want to persist these files, your backend still has to process, store the file (s3 or local), make a DB call to create a reference to the stored location or URL etc. I can't see how the data URLs bypass any of that – Trent Dec 13 '19 at 02:25
  • 1
    Or are you referring to just storing the base64 in the document itself? That's awfully insecure – Trent Dec 13 '19 at 02:27
  • @Trent OP's presumably storing the HTML from the editor already. My read of their question is they're asking if they have to take separate steps to handle files. Storing data URLs in the document itself isn't the slightest bit insecure; it *is* inefficient as it incurs 33% additional bandwidth and can't be cached. The trade-off of not having to do any additional work may be compelling enough to accept that, though. – ceejayoz Dec 13 '19 at 02:28
  • So guys, do I have to write a code in the controller? – TheBAST Dec 13 '19 at 02:43
  • [Storing image in database directly or as base64 data?](https://stackoverflow.com/questions/9722603/storing-image-in-database-directly-or-as-base64-data) check think link for more clarification. It is not a good practice to store the image as base64 and serving in HTML. So yes you will have to process it in backend. – Anuj Shrestha Dec 13 '19 at 04:19
  • Hey guys, can you give me a sample code ? – TheBAST Dec 13 '19 at 07:00
  • @TheBAST That's not really how it works here. – ceejayoz Dec 13 '19 at 14:17

0 Answers0