none
Unable to upload the files on server by using AJAX on IE 11 on update version 11.0.21 by using the https RRS feed

  • Question

  • Unable to upload the files on server by using AJAX on IE 11 on update version 11.0.21

    This problem only occurs on that version on https only and for the rest it works fine. In this also it sometimes gets uploaded successfully.

    Below is the client side code for uploading the image :

    function Upload(fd, url, obj, mp) {
            var xhr = new XMLHttpRequest();
            var ul = {};
            xhr.upload.addEventListener("loadstart", function () {
                ul.percent = 0;
                ul.progress = InitProgress(obj, mp);
            }, false);
            xhr.upload.addEventListener("progress", function (e) {
                var percent = 0;
                var position = e.loaded || e.position;
                var total = e.total;
                if (e.lengthComputable) {
                    percent = Math.floor(position / total * 100);
                }
                percent = percent > 100 ? 98 : percent;
                ul.percent = percent > 10 ? percent - 5 : percent;
                ul.progress.Set(ul.percent);
            }, false);
            xhr.upload.addEventListener("load", function (e) {
                ul.percent = 95;
                ul.progress.Set(ul.percent);
            }, false);
            xhr.onload = function () {
                ul.percent = 100;
                ul.progress.Set(ul.percent);
                try {
                    var resp = this.response;
                    ul.response = JSON.parse(resp);
                }
                catch (e) {
                    ul.response = { status: -1, message: 'An error occurred while uploading file. Please contact Talisma administator. Error code: ' + this.status };
                }
                if (ul.response.status == -100) {
                    location.herf = "LogoutTalisma.aspx";
                    return;
                }
                ul.progress.Done(ul.response);
            }
            xhr.open("POST", url, true);
            ul.xhr = xhr;
            ul.send = function () {
                xhr.send(fd);
            };
            return ul;
        }

    And this is the server side code for upload the image:

    private void InterAttachmentUpload() {
                MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 1");
                HttpFileCollection uploads = HttpContext.Current.Request.Files;
                try
                {
                    MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 2");
                    //FixMarch22(101-240)
                    long UploadLength = -1;
                    UploadLength = Convert.ToInt64(Application["maxAttachmentSize"]);
                    long ActualFileSize = 0;
                    for (int i = 0; i < uploads.Count; i++)
                    {
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 3:" + i.ToString());
                        HttpPostedFile upload = uploads[i];

                        if (upload.FileName == "")
                            continue;

                        #region Extn Check
                        string restrictedAttacmentTypes = "," + System.Web.HttpContext.Current.Application["RestrictedFileFormat"].ToString() + ",";
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 4:" + i.ToString());
                        string extn = Path.GetExtension(uploads[i].FileName);
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 5:" + i.ToString());
                        if (!String.IsNullOrEmpty(extn))
                        {
                            MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 6:" + i.ToString());
                            extn = "," + extn.Trim('.') + ",";
                            if (restrictedAttacmentTypes.Contains(extn))
                            {
                                MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 7:" + i.ToString());
                                error = Resources.WebClient.ErrorStrings.IDS_ATTACHMENTS_FILETYPENOTSUPPORTED;
                                status = -1;
                                return;
                            }
                        }
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 8:" + i.ToString());
                        #endregion
                        #region UploadLengthCheck
                        ActualFileSize += uploads[i].ContentLength;
                        if (UploadLength != -1) //Do a file size check only when UploadLength is specified.
                        {
                            MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 9:" + i.ToString());
                            if (ActualFileSize > UploadLength * 1024)
                            {
                                MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 10:" + i.ToString());
                                string strErrorString = string.Format(Resources.WebClient.ErrorStrings.IDS_ATTACHMENTS_MAXSIZEERRROR, UploadLength + " KB");
                                error = strErrorString;
                                status = -1;
                                return;
                            }
                        }
                        #endregion

                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 11:" + i.ToString());
                        Guid fileId = Guid.NewGuid();
                        string fileName = upload.FileName.Substring(upload.FileName.LastIndexOf("\\") + 1);
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 12:" + i.ToString());
                        using (System.IO.BinaryWriter bw = new BinaryWriter(File.Open(Server.MapPath(@"../Attachments/" + HttpContext.Current.Session.SessionID + "=" + fileId + "=" + fileName), FileMode.Create)))
                        {
                            MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 13:" + i.ToString());
                            byte[] fileBytes = new byte[upload.InputStream.Length];
                            upload.InputStream.Read(fileBytes, 0, Convert.ToInt32(upload.InputStream.Length));
                            bw.Write(fileBytes);
                            MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 14:" + i.ToString());
                            bw.Close();
                        }
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 15:" + i.ToString());
                        if (i==0)
                            str_InterError = "{ \"filenm\":\""+ fileName + "\",\"id\":\"" + fileId + "\",\"sid\":\"" + HttpContext.Current.Session.SessionID + "\",\"size\":\""+ ActualFileSize +"\" }";
                        else
                            str_InterError += ",{ \"filenm\":\"" + fileName + "\",\"id\":\"" + fileId + "\",\"sid\":\"" + HttpContext.Current.Session.SessionID + "\",\"size\":\"" + ActualFileSize + "\" }";
                        MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 16:" + i.ToString());
                    }
                    MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "NSE entering InterAttachmentUpload 17:");
                    error = Resources.WebClient.ErrorStrings.IDS_ATTACHMENTS_SUCCESS;
                    status = 0;
                }
                catch (Exception ex)
                {
                    error = Resources.WebClient.ErrorStrings.IDS_ATTACHMENTS_UNKNOWERRROR + ex.Message;
                    status = -1;
                    MTFileTrace.LogTrace(WebClient.Tracing.TraceLevel.One, TraceClass.Error, TraceTo.Default, LOG_SOURCE, System.Web.HttpContext.Current, "WebClient IntxnAttachmentsUpload. An exception occurred.\tMessage:{0}, \tStack Trace:{1}, \tError Type:{2}", ex.Message, ex.StackTrace, ex.GetType().ToString());
                }
            }


    It gets stuck when the progress shows 95% and no response will come after that.

    Please help us on this.

    Tuesday, September 1, 2015 2:29 PM

All replies

  • Hi NishantJ,

    I recommend you post this in MSDN development forum , as they should have more professional knowledge on AJAX and you may get effective solution timely.

    Best regards,


    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Niko Cheng
    TechNet Community Support

    Wednesday, September 2, 2015 9:10 AM