I am using Web2Py, user images are dynamical and have to be loaded from a different system in the same server therefore they cannot be moved to be contained in the web2py application directory. So I cannot have a relative path to the images. Symbolink links are not an option.
I was thinking the solution could be to serve JPG images from an action call or web service, this way the application can access the local file and return it programatically without having to move a single image. For example a view has the following code:
<li class="file ext_jpg">
<figure class="image_container">
<img src="controller_name/action_serving_images/unique_id_genereted_for_this_image.jpg" alt="">
</figure>
</li>
having the Action:
def action_serving_images(image_id)
#obtain image based on it's unique generated id
return image
Or for the service case:
<li class="file ext_jpg">
<figure class="image_container">
<img src="controller_name/service_serving_images/jpg/image/unique_id_genereted_for_this_image.jpg" alt="">
</figure>
</li>
having the Service:
def service_serving_images():
return service()
@service.jpg
def image(image_id):
#obtain image based on it's unique generated id
return image
- Is any of these options possible?
- How can I fetch the image and return it as a byte stream with the proper content-type so the browser can render it properly?
- Do i need to create a special decorator for JPG in the case of the Service? How?