Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:46:42+00:00 2026-06-18T04:46:42+00:00

I was wondering how to convert Variable-length binary data ( 255216255224016747073700110010100255 ) to a

  • 0

I was wondering how to convert Variable-length binary data(255216255224016747073700110010100255) to a jpeg or png to the web browser?

Example Code:

var Connection = require('tedious').Connection;

    var config = {
        "userName": "user@server.database.windows.net",
        "password": "pswd",
        "server": "server.database.windows.net",
        "options": {
                "database": "db",
                "encrypt": true,
        }
    };

    var connection = new Connection(config);

    connection.on('connect', function(err) {
            console.log("Connected");
        }
    );

var Request = require('tedious').Request;
var result,
    resG;

    function sendResponse() {
        var vals;
            // Convert to string then array
        var resultA = result.toString().split(',');
            // Now I can loop through the data returned
        resultA.forEach(function(val, index, ar) {
            if(vals == null) {
                vals = val;
            } else {
                vals += val;
            }   
        });
        resG.writeHead(200, {'Content-Type': 'text/html', 'Content-Length': vals.length});
        //console.log(vals);
        //resG.end("<img src=\"data:image/jpg;base64," + vals + "\" />");
            // Output data returned from db as string
        resG.end("" + vals);
    }

    function executeStatement() {
         request = new Request("SELECT Photos FROM dbo.tbl WHERE FarmerFirstName='someName' AND FarmerLastName='someLastName'", function(err, rowCount) {
                if (err) {
                    console.log(err);
                } else {
                    console.log(rowCount + ' rows');
                }
            });

            request.on('row', function(columns) {
                columns.forEach(function(column) {
                    result = column.value;
                });
            });

        request.on('doneInProc', function(rowCount, more) {
                    // Got everything needed from db move on to sending a response
            sendResponse();
        });

            connection.execSql(request);
    }

var http = require('http'),
    director = require('director');

var router = new director.http.Router({
    "/": {
        get: executeStatement
    }
});

var server = http.createServer(function (req, res) { 
  // set global res var
  resG = res;
  router.dispatch(req, res, function (err) {
    if (err) {
      res.writeHead(404);
      res.end();
    }
 });
});

server.listen(80);

I’m using tedious for my db connector and director as my router.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:46:43+00:00Added an answer on June 18, 2026 at 4:46 am

    The result is already an array of bytes for the Image. You do not need to do any fancy transformations on it. This should work.

    function sendResponse() {
        resG.writeHead(200, {'Content-Type': 'image/jpeg', 'Content-Length': result.length});
    
        resG.end(new Buffer(result));
    }
    

    or if you want to serve it as part of an HTML page, this:

    function sendResponse() {
        resG.writeHead(200, {'Content-Type': 'text/html'});
    
        var vals = (new Buffer(result)).toString('base64')
    
        resG.end("<html><body>" +
            "<img src=\"data:image/jpg;base64," + vals + "\" />" +
            "</body></html>");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there was a tool to convert a path data like
I was wondering if there was any way to convert a variable of type
I'm wondering how to convert the following code to output those lines into a
I am wondering how do you convert JPG,GIF and PNG images into real .ICO's.
I was wondering how can convert CGcolorRef to UIColor ? I have created a
Hey, I'm just wondering how to convert a numerical date into text format in
I was wondering if it is possible to convert a wpf application to silverlight
I am wondering how exactly I can convert a location (X Y Z) to
I was wondering if anyone knows how to automatically convert PDF's to JPGs in
I was wondering what the easiest way is to convert an integer to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.