'Loading Images from PC using Glide in android

I need to use Glide normal way, but loading Images from PC connected to same local network. Is this possible ?

Thanks,



Solution 1:[1]

I suppose the easiest way would be to setup HTTP server on the local PC. Although you might have to additionally configure Glide to download images without SSL (or setup server to use SSL which is more complicated).

Below is the simple Python server you could use. And I really should stress out that this is not a good production-ready solution. It's just a simple sketch for development purposes.

from http.server import *


class MyHandler(BaseHTTPRequestHandler):

    def _set_png_response(self):
        self.send_response(200)
        self.send_header("Content-type", "image/x-png")
        self.end_headers()
    
    def _set_jpg_response(self):
        self.send_response(200)
        self.send_header("Content-type", "image/jpeg")
        self.end_headers()

    def do_GET(self):
        fileName = self.path.strip("/")
        try:
            pngFile = open(f"{fileName}.png", 'rb').read()
            self._set_png_response()
            self.wfile.write(pngFile)
        except:
            try:
                jpgFile = open(f"{fileName}.jpg", 'rb').read()
                self._set_jpg_response()
                self.wfile.write(jpgFile)
            except:
                try:
                    jpgFile = open(f"{fileName}.jpeg", 'rb').read()
                    self._set_jpg_response()
                    self.wfile.write(jpgFile)
                except:
                    self.send_error(404)


def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
    server_address = ('', 8000)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()


if __name__ == "__main__":
    run(handler_class=MyHandler)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 0awawa0