0

In my html webform, I have this

<input type="file" id="txtUploadFile" accept="image/*" onchange="changetext();" />

However, I am not able to read the image data I'm trying to upload since most functions are not available for IE8. Such functions are

Image()
XDomainRequest()
FileReader()
or this.files[0]

I want to be able to send image data to server, so I can get a binary stream or whatever so that I can pass that something to my c# code which saves the picture in my sql database.

My C# code is as follows:

public SRLogoPhoto SaveSRLogoPhoto(string filePath)
{
    DataSet ds = null;
    Hashtable param = new Hashtable();
    SRLogoPhoto srlp = new SRLogoPhoto();

    try
    {

        System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

        Byte[] b = new Byte[fs.Length];
        fs.Read(b, 0, b.Length);
        fs.Close();
        SqlParameter P = new SqlParameter("@Picture", SqlDbType.VarBinary, b.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, b);

        string sqlStr = "UPDATE SRSiteLogo SET srImage = @Picture ";

        param.Add("Picture", P);

        ds = dbHelper.GetDataSet(sqlStr, param);

    }
    catch (Exception ex)
    {
        srlp.Error = "SaveSRLogoPhoto() web method failed on call to dbHelper.GetDataSet - " + ex.Message;
    }

    return srlp;
}

^This currently works when I upload image on my local machine. But when I deploy my webcode on the server, this won't work since it cannot find the filepath I'm trying to pass. Thats why I need to be able to read the data on my html page(javascript/or any language that I can use in an html file)

Thank you in advance. I really need this.

  • Use javascript to read your image as binary and send that instead of file to your WS. After that you can use: http://stackoverflow.com/a/7391276/1707033 to read the images data properly ... – HellBaby Jun 13 '14 at 07:23
  • ok will try this. i'll search for how to read my image as binary then. – ifallelsefailthenstackoverflow Jun 13 '14 at 07:46
  • Hi @HellBaby, i have searched for reading my image as binary but that needs html5. I am not using html5. is there any other way? – ifallelsefailthenstackoverflow Jun 13 '14 at 08:25
  • http://www.journeyintocode.com/2013/11/reading-binary-data-with-file-api-and.html -> this is a good example IMHO... – HellBaby Jun 13 '14 at 08:40
  • I'm getting 'FileReader is undefined' whenever i try to make a new FileReader.. it seems as though its not supported in my end. How do i make it work? Do I need to include something or etc? @HellBaby – ifallelsefailthenstackoverflow Jun 13 '14 at 09:07
  • I think you can use: https://github.com/Jahdrien/FileReader -> which is a file reader polyfill created for 'shity' browsers like IE 9 and lower. – HellBaby Jun 13 '14 at 10:47
  • Use HTML5 Cross Browser Polyfills https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills – bedna Jun 16 '14 at 07:00
  • I'm not really sure how to use these polyfills. I'm a newbie. And there are no examples on how to use it. I downloaded the whole zip but don't know what to do. I only need the filereader. I'm currently trying moxie. can you help pls @bedna – ifallelsefailthenstackoverflow Jun 16 '14 at 09:22
  • besides we do not use apache server so .php files wont work @bedna – ifallelsefailthenstackoverflow Jun 17 '14 at 06:10
  • @AedzMigraso For older browsers (IE) you find polyfils as mOxie, FileReader.js, FileAPI, idb.filesystem.js or ... Everyone has their description, where is the problem? – bedna Jun 18 '14 at 10:15

0 Answers0