Click Here to signup for my newsletter to receive all the latest information and for your chance to win cool stuff.

Sunday, March 18, 2018

Using Slim Upload with ASP .NET Core Form Post

Using Slim Image Upload with ASP.NET Core Form Post

View Model

Public Boolean HasImage {get;set;} // Used to preload existing image and to know if image has been removed on post back.

Public string Image {get;set;} // Holder for the Image Object to come back through the form post

Public Guid Guid {get;set;} // Guid (generated on first postback but supplied back to display existing image on reloading form.  Can use same Guid to save in azure blob storage etc.

Pubic string Description {get;set;} // other field example

Public string Notes {get;set;} // other field example


Add hidden fields to form postback

 <input id="HasImage" asp-for="HasImage" hidden />

<input asp-for="Guid" id="Guid" hidden />

Add div class for slim.  Style as necessary for width / height or do that dynamically.  Can by dynamically scaled, and positioned.


<div class="slim"></slim>

Javascript for dynamically resizing inside a bootstrap panel.  SlimHolder is the panel pane.  The javascript runs on the window.resize.


var myWidth = $('#slimHolder').width();

var myHeight = $('#slimHolder').height();

var mySize = 0;

if (myWidth < myHeight) {

     mySize = myWidth;


else {

      mySize = myHeight;




var myLeftOffset = (myWidth - mySize) / 2;

if (myLeftOffset > 0) {

      $('.slim').css({ 'marginLeft': myLeftOffset + "px" });


else {

      $('.slim').css({'marginLeft': 0 + "px"});



Slim Initialisation


This can be done on page load or when the slim is bought into view. For example if the slim div is on a pane of a tab panel the initialisation can be executed when the tab pane is brought into view and a flag checked to see if the slim div has already been initialised.  The Download Image is an action of the Controller that returns the image.  If an existing image exists, the image is loaded by slim.  After load the “Image” holder is cleared to prevent the existing image loaded being posted back with the form data.




     didRemove: ImageRemoved,

     defaultInputName: "Image",

     label: "Drop image here or click to select file",

     ratio: "1:1",

     minSize: "100,100",

     size: "600,600",



 ImageInitialised = true;

 if (document.getElementById("HasImage")).checked) {

      let myImageName: string = (document.getElementById("Guid")).val();

      if (myImageName != null && myImageName.length > 0) {

      $('.slim').slim('load', `/Image/DownloadImage/${myImageName}`,

           function (error,data) {







function ImageRemoved() {

    $('#HasImage').prop('checked', false);



Called after save successful to prevent reposting the image on subsequent saves


function ClearImageUpload() {

    if (ImageInitialised) {





Download Image Controller


Gets the image from a memory stream and returns the FileStreamResult which slim reads and loads into the image.  Note it’s also possible to provide slim with a direct URL to where the image is stored rather than going via a controller if the image is physically available by a direct URL.



public FileStreamResult DownloadImage(Guid guid)


     var myImageFile = File(ImageStorage.GetImageStream(guid), "image/jpeg", $"{guid}.jpg");

     return myImageFile;



Async Form Postback Controller

In the sample given the image is stored in a memory stream but can be streamed directly to Azure Blob Storage or other stream provider to save the image.




public JsonResult UpdateImage(ImageViewModel image)


            if (ModelState.IsValid)




                         var myImageResult =  JsonConvert.DeserializeObject<ImageResult>(InventoryItem.Image);

                      if (myImageResult.output != null)


                                using (var myStream = new MemoryStream())




                                image.HasImage = true;

                                Image.Guid = Guid.NewGuid();



                        // need to save the image view model here to keep the other associated data.

                        // Save view model back to a data model or other (not provided in example)

        // Next return back to the form ajax data that can be processed back on client side like    the new Guid, or a more advanced object indicating save state etc.

                        return Json(Image.Guid);




return Json(false); // save failed return back an object, or some other status that can be read in the  ajax success.



Image Result Class

The class that the JSON Object created by slim is deserialized into.


        public class ImageResult


            public MemoryStream GetImageStream()


                byte[] bytes = Convert.FromBase64String(output.image.Substring(output.image.IndexOf(",")+1));

                return new MemoryStream(bytes);



            public Bitmap GetBitmap()


                return new Bitmap(GetImageStream());



            public ImageResultInput input { get; set; }

            public ImageResultOutput output { get; set; }

            public class ImageResultInput


                public string name { get; set; }

                public string type { get; set; }

                public int? width { get; set; }

                public int? height { get; set; }

                public int? size { get; set; }


            public class ImageResultOutput


                public string name { get; set; }

                public string type { get; set; }

                public int? width { get; set; }

                public int? height { get; set; }

                public string image { get; set; }





The javascript AJAX Form Post Back method


function Submit() {

        var myData = $(‘#formName}’).serializeArray();

        if (this.Validate()) {


                type: 'POST',

                url: ‘/Image/UpdateImage/’,

                data: myData,


                dataType: 'json',

                success: (data) => { function() { ClearImageUpload(); // do whatever },

                error: (data) => { // do whatever},

                complete: () => {

                    // do whatever






Sunday, August 13, 2017

Google Sky

Fly through space with Google Sky


Novel Video Trailers

Thinking back to the second video trailer I put together for my novel Elijah Hael - The Genetic Code. This is one of my favourites, what do you think? Does the short clip inspire you to read the novel? If not, do you have a favourite novel trailer you want to share that does?

Tuesday, February 21, 2017

Faith and Autism

A little more to the left I thought, as I turned the web cam.  The image in the Skype window on the screen now showed a little of my desk and my head from the shoulders up.  “Lucky I shaved this morning,” I whispered to myself. 

Time to connect up.  I clicked on Jill’s contact details.  Today I was preparing to work on an article about faith and autism.  Writing articles about faith and how that plays in people’s lives has become part of my regular work life as a result of my Conversations with a Christian articles. 

Jill’s picture appeared as the connection established.  She brushed her long raven black hair away from the side of her face. Her voice carrying an American accent echoed from the desktop speakers saying, “Hello.”   

 “Hi,” I replied, hoping my microphone was setup correctly for her to understand my Australian twang.

Jill took a sip from what appeared to be a cup of tea, which prompted me to glance towards my morning coffee. I failed to realise at the time I had grabbed my daughters My Little Ponies Coffee mug from the cupboard.  I typically grab the first one in line, and I did this morning without thinking.  I quickly shoved the cup out of the camera’s eye.  I didn’t want information getting out I use a My Little Ponies coffee cup.  Next thing, people will start calling me a Brony.  A nickname for adult men who watch My Little Ponies.  Ok, I do admit, in my daughter’s younger years, I sat through one or two episodes.

“Why do people try to deconvert people?” Jill said.

“You mean the atheists in the Christian discussion groups attempting to convince people there is no God?” I replied.  That is where I virtually met Jill, in amongst several other people discussing Christianity on Facebook.

“It’s a real issue for me.” She paused. Her eyes stared off to the left focusing in the distance. “I’ve mentioned to you before that one of my teenage sons is autistic.”

“Yes, you did.” I replied.  I recollected the occasion when I discussed Rosalind Picard, director of Affective Computing at M.I.T. and works with autism. A notable quality of Rosalind is that she talks openly about her Christian faith. I continued, “Does faith help with your son’s autism?”

Her almond eyes returned to the camera and glistened with many experiences, some glittered pain, and others shined joy. “Well, it’s just that my son can feel overwhelmed at times.” She took a sip from her cup before continuing. “He’s got a lot going on in his head that none of us can relate to.” Her lips straightened. “It’s like, he’s on one side of a piece of sheer glass and we are on the other.  Separated by an invisible force.” Her fringe drooped, shrouding her eyes as her head tilted down. “Sometimes he gets really frustrated and depressed when things are out of his control or not going his way.” She returned her focus to the camera. A blank expression hid an attempt to suppress her feelings. “He says life is pointless and that he wishes his brain didn’t give him these problems.”

I stayed silent as she took a moment.  Then the strangest thing happened.  Her lips upturned into a gentle smile and her eyes sparkled with hope. “He has a book called God gave us heaven. It’s for little kids, but he likes it a lot.” Her voice carried a sense of gladness. “He gets very excited and happy about living with God one day. The book also reminds him that he has a purpose here on Earth. His life means something. It’s not pointless.”

I pondered the transformation of seeing Jill’s expression move from pain to joy inspired by hope.

She continued, “He has a fairly good understanding of basic doctrine concerning God, thanks to William Lane Craig’s children books.”  The happiness washed from her cheeks. “I would hate to see the effect those atheists would have on him.  Telling him God does not exist. Telling him he is deluded.” Her hand tightened around her cup. “Telling him he had been lied to.”  A lonesome tear welled in her eye as she added, “He cries when he reads the part there will be no more tears or sadness, only good things.” She wiped the moisture from her eye. “It really moves him a lot.”

I asked, “And what about you Jill. How does faith help you?”

“I pray for Wisdom, and strength.” She blinked longer than normal, as if giving herself time to say a silent prayer before adding, “Jesus carries me through the days and nights.”

A visual came to my mind after listening to Jill.  A child holding their favourite toy, a stuffed teddy with big fluffy ears, a large black nose and shiny auburn eyes.  A teddy that keeps the child safe during the night and contented during the day.  Then a man comes along, telling the child they don’t need the toy, the teddy isn’t real, its effects are imaginary.  The man grabs the teddy’s ear, pulling against the child’s grasp.  The child eyes flooded with tears. A moment later, they overflowed into streams cascading down his tender face. He clung onto to his source of hope with every ounce of energy he could muster as he panted for breath between gulps of sadness. Then the teddy, his best friend, was gone. Snatched, stolen from his arms, leaving him alone surrounded by the sound of his own cries.

Faith for some people is like a teddy bear to a young child.  Hope which comforts them during the night and carries them through the day.

A study published in the American Journal of Psychiatry1 titled Religious affiliation and suicide attempt found subjects with no religious affiliation were more often lifetime suicide attempters, reported more suicidal ideation, and were more likely to have first-degree relatives who had committed suicide than religiously affiliated subjects.

Facts that people who wish to take faith away from others should consider.

Thank God for faith. A gift he provides.

Thank God for Jesus Christ.

Thursday, January 19, 2017

Even Headphones - Redefining the listening experience

Received a set of Even Headphones today. What separates Even Headphones from normal headphones is they calibrate to the characteristics of the listeners hearing. This is achieved by playing 8 sample sounds to each ear. On each sample, the listener selects when they first hear the sound. This allows the headphones to adjust the loudness of different frequencies per ear to the users hearing. The adjustments create a deep listening experience bringing out sounds the user may not hear correctly, and or equally between ears with traditional headphones.

Even is challenging the basic precepts of the audio industry that we all hear the same and that our hearing is perfect. Even think it's time our ears get the attention and love they deserve.

Friday, January 29, 2016

Turning dreams into reality

Eight years ago Jared Mann, a young man with a dream, came to my company Software Development Pty Ltd with an idea to turn a spreadsheet he had created into a commercial software program. That idea was realised into what is known today as Pairtrade Finder. A pair trading software package for Microsoft Windows. He successfully marketed the solution across the globe, earning his freedom to live life as he wants, leaving behind his full-time job at an investment bank. Over the 2015 Christmas period, Jared sold the project to a U.K. company, Event Driven Investor Research LLC, who will continue to grow and market the software. As a developer, it’s great seeing people’s dreams come to life. It’s what I wish for all persons whom we help to turn their dreams into reality. Jared continues to innovate and fill niches in the marketplace as a successful entrepreneur.

Tuesday, June 16, 2015

Excellent Follow-up. Romance adventure and science fiction all in one

"Let me start by saying I loved this book (Elijah Hael - The Genetic Code). It had a nice steady pace that kept you wanting more. The interaction between the 3 main characters; Elijah, Castiel, and Sophia is believable. This book is the second book in the Elijah Hael series however, you do not need to have read the first book to get this story it is completely stand alone. This book was very emotional and I did find myself crying so be prepared for that. Character development was spot on pacing was excellent and the story was engaging and immersive. I just wish that it had ended that is really my only complaint I love falling into Elijah Hael’s universe. Again I can not state how much I truly enjoyed this book!!!"

Rating 9.5/10

Recommendation: Genuinely good writing and story telling seekers will find what they are looking for with this book. Fans of the Elijah Hael series will love this installment.

Victoria Roberts

Thanks Victoria, appreciate your review.