Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Providing resources parallel to the datalayer over HTTP

Providing resources parallel to the datalayer over HTTP

seinsiedler
New Poster

Hello people,
I hope communication is the correct topic for this question.

Situation: I am currently working on a camera app. The app may get a GUI provided via package-www over snap-craft, which still requires a back-end. Due to bandwidth constraints these the images are currently provided over HTTP in binary form.

What is the best/desired practice for this?
What library would you advise to use to host the HTTP server?
Should the URL be provided in the datalayer?
What would be the/your preferred format for images?

1 REPLY 1

Sgilk
Frequent Contributor

Hi @seinsiedler ,

I'm not sure anyone is going to be able to provide best practices on this specific application. A lot of your questions are really user preference.

I can share my own experience on this topic though.

  1. What library would you advise to use to host the HTTP server?
    1. I have used Python Flask to host an HTTP image/video server that handles file sizes up to ~50MB.
    2. Any HTTP client will work, but I could recommend Axios JS if working in an HTML frontend.
  2. Should the URL be provided in the datalayer?
    1. This depends on the architecture and functionality of your process. This doesn't necessarily need to be provided in the datalayer if it doesn't need to be shared with other processes.
  3. What would be the/your preferred format for images?
    1. Again, this is up to you. If you are using binary/base64 to encode the resources for transfer, it should support any type. I have used png, jpg and mp4.

Please let me know if you have any other questions! An example Flask server implementation is below.

from xml.etree.ElementTree import tostring
from flask import Flask
from flask_cors import CORS
import os

app = Flask(__name__,
            static_url_path='', 
            static_folder='Resources/')

CORS(app)

dir_path = 'Resources/'


@app.route('/directories')
def directories():
    dirs = []
    try:
        for path in os.scandir(dir_path):
            if path.is_dir():
                print(path.name)
                dirs.append(str(path.name))
        return dirs
    except Exception as e:
        print(e)


@app.route('/fileCount/<target>/<folder>')
def fileCount(target = None, folder = None):
    print(dir_path + target +'/' + folder)
    count = 0
    try:
        for path in os.scandir(dir_path + target +'/' + folder):
            if path.is_file():
                count += 1
        return str(count)
    except Exception as e:
        print(e)

app.run(host="0.0.0.0")
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist