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 6102143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:34:49+00:00 2026-05-23T13:34:49+00:00

I am having trouble converting an image into bytes and saving it in database.

  • 0

I am having trouble converting an image into bytes and saving it in database.

Here is the description,

I have an image that will be send from a remote device to the web server using HTTP POST.

so what I am doing is I ask them to sent the image to me.

Since the data is sent in POST i assume they will send me the Bytes by converting the bytes into string using

byte[] img = FileUpload1.FileBytes;
Encoding enc = Encoding.ASCII;
string img = enc.GetString(img);

Then they make a WebRequest using HTTPWebRequest and append this image in HTTP POST.

The Whole Code for making the request —

    WebRequest request = WebRequest.Create(url);
    request.Method = "POST";


    //Create the POST Data

    FileUpload img = (FileUpload)imgUpload;
    Byte[] imgByte = null;
    if (img.HasFile && img.PostedFile != null)
    {
        imgByte = imgUpload.FileBytes;
    }
    string imgPh = null;
    Encoding enc = Encoding.ASCII;
    if (imgByte != null)
    {
        imgPh = enc.GetString(imgByte);
    }
    string postData = "sid=8062BD53EB4552AD6D0FBB7E5DC5B7AF&status=Y&uid=123456789012&fname=Dinesh Singh&lname=Malik&ftname=Balwan&yrbirth=1988&gender=Male&address1=Address1&address2=Address2&address3=Address3&address4=Address4&imagePh=" + imgPh;


    byte[] post = Encoding.UTF8.GetBytes(postData);


    //Set the Content Type
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = post.Length;

    Stream reqdataStream = request.GetRequestStream();
    // Write the data to the request stream.
    reqdataStream.Write(post, 0, post.Length);

    reqdataStream.Close();

    // If required by the server, set the credentials.
    request.Credentials = CredentialCache.DefaultCredentials;
    WebResponse response = null;
    try
    {
        // Get the response.
        response = request.GetResponse();

    }
    catch (Exception ex)
    {
        Response.Write("Error Occured.");
    }

On the Page to which Request is made I am getting this image again into bytes using

    Encoding enc = Encoding.ASCII;

    byte[] imagePhoto = enc.GetBytes(postData["imageph"]);

From Here I save it into my Database

But when I retrieve the image using the Handler, it does not show the image.


The issue is the conversion of the image from byte[] to string and then converting string into byte[] at the Web Server. (Because when I save the image directly without this conversion using TestPage on server it shows the image.)

So What am I doing wrong in this.

Also is there any way in the above code to get the data of HTTP Post as received by the Web Server (retrieve HTTP Headers).
I want to retrieve this data received to sent it back to the Other Development to develop the request at the device in the same format as I am receiving in the HTTP Web Request URL

Any help would be appreciated.

  • 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-05-23T13:34:50+00:00Added an answer on May 23, 2026 at 1:34 pm

    Ok I think finally I figured it out.

    What I did was –

    Image -> byte[] -> Convert.ToBase64String -> Append The String Data to Post Request

    At the Server-

    Get the Post Data -> Convert.FromBase64String -> byte[] -> Insert into Database

    Works Great…:)

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble converting some code from VB6 to VB.NET (I don't have
I'm having trouble converting an array into correctly nested HTML. Assuming I have an
I am having trouble understanding converting to and from bytes, or bytes in general
I'm having trouble converting the following SQL-statement to LINQ-to-entities: SELECT l.* FROM locations l
I am having some trouble converting an old project from VS6 to VS2005. At
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am having trouble converting this code into extension method syntax: var query =
I've been having trouble converting the following fairly straight forward c# code into vb.net
I'm new to C++ so I'm having trouble converting this into C++. Is there
I'm not that familiar with Linux so I'm having trouble converting the following command

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.