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

  • Home
  • SEARCH
  • 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 8056211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:38:29+00:00 2026-06-05T08:38:29+00:00

my application gets image from clipboard and saves it to server. getting image is

  • 0

my application gets image from clipboard and saves it to server.
getting image is done through java and javascript.
my aspx codebehind receives this data (base64) and writes to file.
here is my code

  byte[] buffer = new byte[Request.InputStream.Length];
    int offset = 0;
    int cnt = 0;
    while ((cnt = Request.InputStream.Read(buffer, offset, 10)) > 0)
    {
        offset += cnt;
    }
    fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png";
    string base64 = System.Text.Encoding.UTF8.GetString(buffer);

    byte[] bytes = Convert.FromBase64String(base64);
    System.IO.FileStream stream = new FileStream(@"D:\www\images\" + fileName, FileMode.CreateNew);
    System.IO.BinaryWriter writer =new BinaryWriter(stream);
    writer.Write(bytes, 0, bytes.Length);
    writer.Close(); 

my problem is base64 . i get this string as utf8 encoded. seems this tampers the image and i am not able to open or view them.

[EDIT]
Here is the java code that creates the data

StringBuffer sb = new StringBuffer();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
sb.append("data:image/").append("png").append(";base64,").append(Base64.encode(stream.toByteArray()));

so i will get a string like this
data:image/png;base64,iVBORw0KGgoA..
and using ajax i posts this string to my aspx page

  • 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-05T08:38:30+00:00Added an answer on June 5, 2026 at 8:38 am

    You should remove the data:image/png;base64, prefix when you read the input stream before base64 decoding. For example you could split at the ,:

    byte[] buffer = new byte[Request.InputStream.Length];
    Request.InputStream.Read(buffer, 0, buffer.Length);
    string data = Encoding.Default.GetString(buffer);
    string[] tokens = data.Split(',');
    if (tokens.Length > 1)
    {
        byte[] image = Convert.FromBase64String(tokens[1]);
        string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png";
        string path = Path.Combine(@"D:\www\images", fileName);
        File.WriteAllBytes(path, image);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a bunch of data out from a java application that gets consumed
My application only gets image and it's metadata from ios device using ALAssetsLibrary .
I'm making an application which uses MANY images. The application gets the images from
We have a web application that gets its data from a certain database. The
I have a Silverlight 4 application which gets data from a silverlight enabled WCF
I'm working on an MVC3 Razor web application which gets it's page decoration from
I'm building an application to retrieve an image from internet. Even though it works
I am fetching a lot of thumbnails in my application from a remote server
I'm trying to save a copied image from the clipboard but it's losing its
I have a java application that will take the image as an input and

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.