Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phil Veloso 38 posts 251 karma points
    Sep 12, 2018 @ 15:28
    Phil Veloso
    0

    Data image - ReadAllBytes TimeOut

    Hello all,

    I have an issue whereby I am trying to create a data image but encounter an timeout issue when rendering the page.

    Can someone please shed some light as the possible reasons why?

    Here is my code below:

        // Loop sections
        foreach ( var item in @node.DescendantsOrSelf("Section") )
        {
            string image = "....path....";
    
            byte[] array = System.IO.File.ReadAllBytes( Server.MapPath(image) );
    
            string baseCode = Convert.ToBase64String(array);
    
            contentList.Add( string.Format( 
                    @"{{ text: ""data:image/jpeg;base64,{0}"" }}",  
                    baseCode
                ) 
            );
    
        }
    
  • Phil Veloso 38 posts 251 karma points
    Jun 02, 2019 @ 13:06
    Phil Veloso
    100

    Encase anyone needs help, this was my solution:

    using ( MemoryStream ms = new MemoryStream() )
    {
        var webClient = new WebClient();
        string imageUrl = image;
        if ( type == "local" )
        {
            imageUrl = "https://" + @HttpContext.Current.Request.Url.Host + "/" +image;
        }
        byte[] imageBytes = webClient.DownloadData(imageUrl);
        return Convert.ToBase64String( imageBytes );
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft