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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:14+00:00 2026-06-11T12:32:14+00:00

At work we are trying to upload files from a web page to a

  • 0

At work we are trying to upload files from a web page to a web service using html 5/javascript in the browser end and C# in the web service. But have some trouble with encoding of some sort.

As for the javascript we get the file’s binary data with help from a FileReader.

var file = ... // gets the file from an input
var fileReader = new FileReader();
fileReader.onload = dataRecieved;
fileReader.readAsBinaryString(file);

function dataRecieved() {
  // Here we do a normal jquery ajax post with the file data (fileReader.result).
}

Wy we are posting the data manually and not with help from XmlHttpRequest (or similar) is for easier overall posting to our web service from different parts of the web page (it’s wrapped in a function). But that doesn’t seem to be the problem.

The code in the Web Service looks like this

[WebMethod]
public string SaveFileValueFieldValue(string value)
{
  System.Text.UnicodeEncoding encoder = new UnicodeEncoding();
  byte[] bytes = encoder.GetBytes(value);
  // Saves file from bytes here...
}

All works well, and the data seems to be normal, but when trying to open a file (an image as example) it cannot be opened. Very basic text files seems to turn out okay. But if I upload a “binary” file like an image and then open both the original and the uploaded version in a normal text editor as notepad to see what differs, it seems to be wrong with only a few “invisible” characters and something that displays as a new line a few bytes in from from the start.

So basicly, the file seems to encode just a few bytes wrong somewhere in the conversions.

I’ve also tried to create an int array in javascript from the data, and then again transformed to a byte[] in the web service, with the exact same problem. If I try to convert with anything else than unicode (like UTF-8), the data turns out completly different from the original, so I think om on the right track here, but with something slightly wrong.

  • 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-11T12:32:15+00:00Added an answer on June 11, 2026 at 12:32 pm

    The request itself is text, so binary data is lost if you send the wrong enc-type.
    What you can do is encode the binary to base64 and decode it on the other side.

    To change the enc-type to multi-part/mixed and set boundaries (just like an e-mail or something) you’d have to assemble the request yourself.

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

Sidebar

Related Questions

I am trying to upload files to a web server using System.Net.WebClient.UploadFile but I
I am trying to upload files using the FileReference class. Files >2MB all work
I try to upload a file using asmx service from windows forms. I have
I have a pretty straight forward uploadified page that allows users to upload files,
I am trying to upload a file from browser, then make one thumbnail from
I am trying to upload some files using the multiple upload file field. The
I have the following web service that allows me uploading files: [WebService(Namespace = http://tempuri.org/)]
Im trying to work out how to get the value from one setting in
I am trying to work out how I can insert the string End into
I'm currently having an issue where I have a javascript object that is trying

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.