Uploading a photo to an external database

Hi I was wondering is there a way of uploading a photo to outsystems and being able to store it in an SQL database or do i have to store it locally within outsystems?

When i tried to pass it as a binary data type to the SQL database it came back with 0 bytes within the database - so it is going through but it cannot be saved.

Alongside this, is it simple to pull the photo from either a local or external database and be able to display it on a user profile?


Thank you!

mvp_badge
MVP
Solution

Hi beginningtester,


It's possible to save a binary data in the OutSystems database or in an external one.

In your case, you're probably not passing the binary data right when inserting the file in the database and that's why you are getting the null binary when you fetch the record from the database. Check the OML in attachment for a very simple example on how to store an image in the DB and show it on the screen.

However, as a rule of thumb, SQL databases are expensive and small, if you want to store a lot of blobs like images and documents. It's way cheaper to store them externally in external systems for that effect like Azure Blob Storage.

It all depends in the use case, of course. If you want to store a few images and you're sure your app won't reach a point where you have thousands or millions of photos, then OutSystems database might be the best solution.


Kind Regards,
João

ReactiveSandbox8.oml

Hi Joāo,


Thank you for your reply and for your sample code! it was very helpful. Behind the upload button I'm having trouble setting the source for the 'CreateImage' table because it's coming from an external database I can't set the binary data and imageName to the data thats uploaded. Do you have any advise?


Thank you!

Screenshot 2022-02-09 at 14.02.53.png

mvp_badge
MVP

Hi Ailish,


If you hover the mouse just behind the Source property, you should see a + sign to expand it:


When you expand, you can then set, attribute per attribute, the values you are going to insert in the database:


In my example above, the attributes displayed under Source are the User attributes, but in your case, it would be the userPhoto attributes.


Kind Regards,
João

Hi Joāo,


Brilliant thank you so much for your help!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.