Saturday, 7 July 2018

Reading and returning jpg file in Python, ASP.NET?

I have an image.asp file, using Python, in which I am attempting to open a JPEG image and write it to the response so that it can be retrieved from the relevant link. What I have currently:

<%@ LANGUAGE = Python%>
<%

path = "path/to/image.jpg"

with open(url, 'rb') as f:
    jpg = f.read()

Response.ContentType = "image/jpeg"

Response.WriteBinary(jpg)

%>

In a browser, this returns the following error:

The image "url/to/image.asp" cannot be displayed because it contains errors.

I suspect the issue is that I am just not writing contents of the jpg file correctly. What do I need to fix?



from Reading and returning jpg file in Python, ASP.NET?

No comments:

Post a Comment