Invalid JSON primitive in RadAsyncUpload

2 posts, 0 answers
  1. Mike
    Mike avatar
    6 posts
    Member since:
    Sep 2012

    Posted 18 Dec 2012 Link to this post

    I am receiving an error message when trying to upload files via the RadAsyncUpload. It is strange because it doesn't seem to happen all the time, and I haven't been able to pinpoint exactly when it happens.  

    The way that I have this setup is that I have a user control called DocumentRepository.  The control is in a RadWindow which is opened by clicking on a LinkButton in the aspx page.  Inside that control, I can click on a button which opens another RadWindow allowing the user to browse for and upload a file.  That uses RadAjaxUpload.

    So to start, I have my aspx page:
    <%@ Register Src="~/secured/IntakeRequest/ascx/DocumentRepository.ascx" TagName="DocumentRepository" TagPrefix="ADAAC" %>
     
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadFormDecorator ID="radFormDecorator" runat="server" DecoratedControls="All" Skin="Office2010Silver" EnableRoundedCorners="false"  />
         
    <telerik:RadAjaxManager runat="server" ID="radAjaxManager1" OnAjaxRequest="radAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="radAjaxManager1">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID="adaacDocumentRepository" UpdatePanelRenderMode="Inline" />
                 </UpdatedControls>
             </telerik:AjaxSetting>
         </AjaxSettings>
    </telerik:RadAjaxManager>
     
    <telerik:RadScriptBlock runat="server">
        <script type="text/javascript">
            function windowCommunicationLog_OnClientBeforeShow(sender, args) {
                var ajaxManager = $find("<%= radAjaxManager1.ClientID %>");
                ajaxManager.ajaxRequest("windowCommunicationLog_OnClientBeforeShow");
            }
        </script>
    </telerik:RadScriptBlock>
     
    <telerik:RadWindow runat="server" ID="windowDocumentRepository" Title="Document Repository" Width="1024" Height="700" VisibleOnPageLoad="false" Behaviors="Close, Move" EnableShadow="true" Modal="true" DestroyOnClose="false" OnClientBeforeShow="windowDocumentRepository_OnClientBeforeShow">
        <ContentTemplate>
            <ADAAC:DocumentRepository runat="server" ID="adaacDocumentRepository" />
        </ContentTemplate>
    </telerik:RadWindow>

    aspx.cs:

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!IsPostBack)

    {

        windowDocumentRepository.OpenerElementID = btnImportDocument.ClientID;

    }

    protected

    void radAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)

     

     

    {
        if (e.Argument == "windowDocumentRepository_OnClientBeforeShow")
        {
            // the only thing this does is bind a repeater with a list of documents already uploaded
            adaacDocumentRepository.BindDocuments();
        }
    }

    Inside the user control adaacDocumentRepository:
    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel2" Skin="Metro" BackgroundPosition="Center" Direction="LeftToRight" EnableSkinTransparency="false"></telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxManagerProxy runat="server" ID="radAjaxManagerProxy1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btnUploadFile">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="btnUploadFile" LoadingPanelID="RadAjaxLoadingPanel2" UpdatePanelRenderMode="Inline" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
     
    <telerik:RadWindow runat="server" ID="windowAddDocument" Title="Import a Document" Width="800" Height="250" VisibleOnPageLoad="false" Behaviors="Close, Move"
                            EnableShadow="true" Modal="true" IconUrl="/images/windowIcon.png">
        <ContentTemplate>
            <div><b>Select a document to upload</b></div>
            <div>
                File:
            </div>
            <div>
                <telerik:RadAsyncUpload  runat="server" MaxFileInputsCount="1" ID="fileUpload1" ControlObjectsVisibility="None" Width="375" />
            </div>
            <div>
                <asp:Button runat="server" ID="btnUploadFile" OnClick="btnUploadFile_OnClick" Text="Upload File" />
            </div>
            <div>
                Browse for a file and then hit the "Upload" button.
            </div>
        </ContentTemplate>
    </telerik:RadWindow>
     
    <div>
        <asp:ImageButton ImageUrl="adddoc.jpg" AlternateText="Add a Document" runat="server" ID="btnUploadDoc" />
    </div>

    ascx.cs file:

    protected void Page_Load(object sender, EventArgs e)
    {
        RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
        manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(radAjaxManager1_AjaxRequest);
     
        if (!IsPostBack)
        {
                windowAddDocument.OpenerElementID = btnUploadDoc.ClientID;
        }
    }
     
    protected void btnUploadFile_OnClick(object o, EventArgs e)
    {
        if (fileUpload1.UploadedFiles.Count == 1)
        {
            string encFileName = Guid.NewGuid() + GetFileExtension(fileUpload1.UploadedFiles[0].FileName);
     
            string uploadPath = Server.MapPath("/documents/" + encFileName);
     
            fileUpload1.UploadedFiles[0].SaveAs(uploadPath);
            BindDocuments(); // this just rebinds the uploaded documents
        }
    }
     
    protected void radAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        // this is just here so I can use radconfirm to do file deletions from the grid
    }


    The json request that is being generated that is causing the error is:

    {
      'isEnabled':'true',
      'uploadedFiles':[
        {
          "fileInfo":{
            "FileName":"Footer Graphic.png",
            "ContentType":"image/png",
            "ContentLength":18389,
            "Index":0
          },
     "metaData":"/wEFwwF7IlRlbXBGaWxlTmFtZSI6IjEzNTU4NzU4MzI1NjFGb290ZXIgR3JhcGhpYy5wbmciLCJBc3luY1VwbG9hZFR5cGVOYW1lIjoiVGVsZXJpay5XZWIuVUkuVXBsb2FkZWRGaWxlSW5mbywgVGVsZXJpay5XZWIuVUksIFZlcnNpb249MjAxMi4yLjkxMi4zNSwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj0xMjFmYWU3ODE2NWJhM2Q0In0NCNiTh2r8IZeBu1RIF0/Xu3qk/w=="
        }
      ]
    },


    When I run it through a validator, it appears as though it is the first part that is causing the error, since isEnabled and uploadedFiles is in single quotes instead of double quotes, and the 'true' needs to be either a Boolean, or a string in double quotes....

    Any ideas as to how I can fix this?  I can't seem to find anybody else that is having this problem.....

    I have not been able to recreate this, but it is definitely happening as I can see the error messages coming in pretty regularly.  Why are those values coming in with single quotes?  What is causing it?  Do I need to hack it somehow or is there a fix?

    It is definitely the posted value from the RadAsyncUpload control:

    ctl00_ctl00_PageContent_PageContent2_windowDocumentRepository_C_adaacDocumentRepository_windowAddDocument_C_fileUpload1_ClientState:{'isEnabled':'true','uploadedFiles':[{"fileInfo":{"FileName":"Footer Graphic.png","ContentType":"image/png","ContentLength":18389,"Index":0},"metaData":"/wEFwwF7IlRlbXBGaWxlTmFtZSI6IjEzNTU4NzU4MzI1NjFGb290ZXIgR3JhcGhpYy5wbmciLCJBc3luY1VwbG9hZFR5cGVOYW1lIjoiVGVsZXJpay5XZWIuVUkuVXBsb2FkZWRGaWxlSW5mbywgVGVsZXJpay5XZWIuVUksIFZlcnNpb249MjAxMi4yLjkxMi4zNSwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj0xMjFmYWU3ODE2NWJhM2Q0In0NCNiTh2r8IZeBu1RIF0/Xu3qk/w=="}]},
     
    Thanks in advance!!!
  2. Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 21 Dec 2012 Link to this post

    Hi Mike,

     
    We have inspected the issue you described by unfortunately could not reproduce it locally. We are also not aware of such known RadAsyncUpload issue so we can not provide a ready solution for it. Please let us know if you succeed to narrow the issue down so it could be reproduce so we could be more helpful. 

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top