-1

So far I found something related to what I am looking for, but I'm not sure if this is what I need: link

How do I convert the file to byte in js and send it to webservices to upload to server.

Example:

JS:

<script>
    webService.UploadFile(Myfilebytes,suc,fail);
</script>

C#:

[Web Method]
public string UploadFile(byte[] Myfilebytes)
{
     //UPloading script
    return "OK";
}
Community
  • 1
  • 1
InGeek
  • 2,532
  • 2
  • 26
  • 36

1 Answers1

0

You don't convert the file to a byte array; it already is one. Your browser manages the responsibility of formatting the data to send to a web service. Typically this is achieved through a POST on a form with an input of type file:

<form enctype="multipart/form-data" action="UploadFile" method="post">
    <input id="image" type="file" />
</form>

Using a WebMethod on the C# side is not possible, however, as POST variables are received through the request information, of which a WebMethod does not provide. You can create a web handler and use the ProcessRequest method to receive this info, but this is not the only way.

CassOnMars
  • 6,153
  • 2
  • 32
  • 47
  • thanks, I found this link http://stackoverflow.com/questions/7431365/filereader-readasbinarystring-to-upload-files/14509092#14509092 , but I can't get it wokk. How can I implement it? – InGeek Jan 24 '13 at 19:25