How to convert image to byte array using javascript only to store image on sql server?

后端 未结 3 1387

I am struggling converting image to byte array using client side script. I have to convert image to byte array, and pass this array to web service , so that the web services

3条回答
  •  不思量自难忘°
    2020-12-01 12:54

    A possible solution to this problem:

    1. Perform a faux-AJAX call to upload the image file (this jQuery plugin has worked wonders for me thus far).
    2. Retrieve the file from the page you post it to via Request.Files.
    3. Perform the Web Method call by using the resulting HttpPostedFile's InputStream property to feed the byte[] parameter of the Web Method call.

    You can obviously do a full page post to a specific URL to perform the same functionality, but I'm a huge fan of AJAX / web method combinations in ASP.NET. Oh, this also assumes you're using ASP.NET to post to the Web Method. :P

    If you don't want to use jQuery, you can implement your own AJAX function using the XMLHttpRequest object in JavaScript. This article has a nice example of how to implement it to perform GET / POST calls to a url.

提交回复
热议问题