0

We are Generating blob value and want to get it inserted into the database through SQL Server. We are able to pass the blob value and through the help of Ajax call we are trying to get it to insert but we are receiving the error Uncaught (in promise) TypeError: Failed to execute 'array buffer on 'Blob': Illegal invocation code. And in WebServices, we are passing it as byte value byte[] BLOB while in SQL we are using var binary(max) to store the value.

async function pdfhandler() {
    let pdfBlob = '1';
    var mystring = "Hello World!";
    pdfBlob = new Blob([mystring]);
    updateblobdata(pdfBlob);
    console.log(pdfBlob);
}

  
function updateblobdata(blobvalue) {
    debugger;
    /// Insert Blob into Database ///
    console.log('updateblobdata called');
    const urlParams = new URLSearchParams(window.location.search);
    const myParamtag = urlParams.get('104');
    const mymodelval = urlParams.get('DuganHosp-0002');

    var wonumval = '104'; var tagnumval = 'DuganHosp-0002';
    var Modeval = 'U';
    var BLOBval = blobvalue;

    $.ajax({

        url: 'TestTool_WebService.asmx/UpdateHtmlBLOBContent',
        data: {
            WoNum: wonumval,
            Tagnum: tagnumval,
            BLOB: BLOBval,
            Mode: Modeval,
        },
        method: 'post',
        dataType: 'json',
        contentType: false,
        processData: false,
        cache: false,
        success: function (data) { },
    });
}

2 Answers 2

1

You can send files only with content-type: multipart/form-data.

function updateblobdata(blobvalue) {
    const formData = new FormData();
    formData.append('blob', blobvalue);

    $.ajax({
        url: 'TestTool_WebService.asmx/UpdateHtmlBLOBContent',
        data: formData,
        method: 'post',
        dataType: 'json',
        contentType: 'multipart/form-data',
        processData: false,
        cache: false,
        success: function (data) { },
    });
}
Sign up to request clarification or add additional context in comments.

Comments

0

No Still its not working.Its not coming to this point for blob value.

 [WebMethod]
    public void UpdateHtmlBLOBContent(string WoNum, string Tagnum, byte[] BLOB, string Mode)
    {
        string htmldoc = null;
        using (SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConStr1"]))
        {

            SqlCommand cmd = new SqlCommand("TestTool_PrototypeprocBlobRun", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Workorder", WoNum);
            cmd.Parameters.AddWithValue("@Equipment", Tagnum);
            cmd.Parameters.AddWithValue("@HTML_blob", BLOB);
            cmd.Parameters.AddWithValue("@MODE", "U");
            con.Open();
            int i = cmd.ExecuteNonQuery();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                htmldoc = "Success";
            }
            dr.Close();

        }

        Context.Response.Write(htmldoc);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.