Forum Discussion

Kallie's avatar
Kallie
Guide
7 years ago

Uploading/saving blog attachment to local server

Hi, 

I'm looking to extend the new responsive design blog board to save blog attachments to our local file server and whenever a blog attachment is downloaded, download it form our file server. 
I'm not so familiar with the API but want to know if this will require writing our own custom blog pages or something we can just add to OOTB blog board.

Thanks

  • Hi Kallie,

    I think the Lithium modules doesn't support such a functionality out of the box. Per default each attachment is related to a blog post and therefore they are stored within the Lithium infrastructure.

    One solution could be using hidden markup and JavaScript snippets:

    You could add something like this

    <div class="lia-js-hidden" data-attchmenturl="YOUR_URL_GOES_HERE"></div>

    via the HTML-Edit-Mode  to your post.

    A small JavaScript (which is added to the BlogArticlePage quilt) could crawl the content for the hidden content and the render the data as you prefer.

     

    To make adding the hidden markup it bit more comfortable to users, you could add customization (a button for example) which injects the stuff above (and asks the user for the attachment url).

     

    Regards,

    Christian

  •  

    Kallie You could technically "hijack" the event handlers on the "Add attachment" button and do your own thing. There are many ways of doing something like that:

    a) the JavaScript File API could be used to send the selected file to your server

    b) FreeMarker also offers some options with Lithiums own http.request context object

    http.request.uploads.name.get("<file_input_name>")

    see: https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=freemarker#l::{"p":"%2Frefer%2FcontextObjects","h":"%23upload"}

    then send the file to your server with a post request somehow...

     

    of course you need to handle the reverse as well, e.g., you need to figure out a way to tell your server which file belongs to which post, then when a user is on post you need to query your server for attachments and so on... why would you want to do that? (just curious)