Saturday, August 19, 2017

mssql, express, and node - working with images

I'm pretty sure no one else has had the experience of sales over selling, over promising the delivery of a product.😅 Am I right?



When the boss came to me with this little project, knowing I couldn't squeeze it into the schedule, I decided it would become my weekend project. After looking at the requirements, I thought it would be cool to stretch my MEAN legs. Except in this case, it would be (MSSQL, Express, Angular, and Node).

There's a few cool aspects of this project, but for this article, I'll just focus on getting the server component running and connecting with Node's MSSQL to the SQL Server.

The requirements were:
  • Must be a HTML5 app
  • Retrieves an image stored in a SQL Server database.
  • Returns images (multiple) based on ID parameter
So here's the snippet.


And the table design was like this:


I figured I would create the Rest APIs, so the product could pull the images from anywhere with Express.

The biggest obstacle I ran into was managing the connection pool. Once, I figured out how to wire it up properly, it was a piece of cake.

To call the API, I used http://localhost:8080/api/images/1.

If I look at the response data in Fiddler, I get something like this back.




So this is an array of 6 images, and the response object is 11043515 bytes which equal roughly 10M - SUPER large for a response object.

So ideally you wouldn't have SQL images stored in your database but rather store the metadata about the image along with the path of the image on a file system.

In the particular instance, it was the customer requirement. I simulated the database with some of my own images and I didn't resize them before storing them. So, in this small sample size - it worked fine and I saw no performance issues, but I definitely wouldn't do this in a production environment.

There were some challenges and a bit of a learning curve, but overall ..... I kind of love this stuff.



No comments:

Post a Comment