priya-zha / Software-Engineering-Project

0 stars 2 forks source link

NFR #1 Compressing the image before sending to handle slow network connection between android and backend #13

Open Manikothakota-git opened 11 months ago

Manikothakota-git commented 11 months ago

Slow network connections between the Android app and the backend can lead to delays.In this updated code, Ihave added the zlib module to compress the image data before sending it. This can help reduce the network latency by sending smaller data over the network. When a client receives the compressed image, it can decompress it for display or further processing.

updated code

import zlib # Import the zlib module for data compression

Compress the image data before sending

        compressed_image = zlib.compress(image.tobytes())

        return send_file(
            BytesIO(compressed_image),
            mimetype="image/jpeg",
            as_attachment=True,
            attachment_filename="annotated_image.jpg"
        )