Convert octet-stream to string or array

Convert octet-stream to string or array

Hello, first timer here.

I am actually using Devextreme to develop a mobile app which is connected to a RESTful service. The service sends the appropriate data as an octet-stream. I need to convert this stream into an array or object of some sorts so that I can use the data that was sent and display the correct result in my app.

This is my db.js file :

  1. (function ($, DX) {
        var dbImpl = {
           url: 'http://master/umbrellamobileservice/product/04',
            _sendRequest: function (type, params) {
                var deferred = new $.Deferred();
                var requestSettings = {
                    url: $.trim(dbImpl.url),
                    type: 'GET',
                 //   crossDomain: true,
                      contentType: "application/json; charset=utf-8",
                                 
                 //   dataType: 'jsonp',
                //    async: false,
                    jsonpcallback: 'Error',

                    success: function (data) {
                        //Is it binary Type?????
                        var content_type =  xml_http_request.getResponseHeader('Content-Type');

                        if (content_type == "application/octet-stream" )
                        {
                       //     document.write(result);     
                        
                            alert('successful..');

                            var blob = new Blob([requestSettings.data]);
                            var link = document.createElement('a');
                            link.href = window.URL.createObjectURL(blob);
                            link.download = "myFileName.txt";
                            link.click();

                            }
                        else
                        {
                            //
                            alert('nope...');
                        }
                      

                    
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert('Error Message: ' + textStatus);
                        alert('HTTP Error: ' + errorThrown);
                    }

                };
                if (params) {
                    if (type == 'DELETE') {
                        if (requestSettings.url[requestSettings.url.length - 1] != '/')
                            requestSettings.url += '/';
                        requestSettings.url += params.toString();
                    }
                    else
                        requestSettings.data = params;
                }
                $.ajax(requestSettings);
                return deferred;
            },
            load: function (loadOptions) {


                if (loadOptions.refresh) {
                    return dbImpl._sendRequest('GET');
                }
            },
            insert: function (params) {
                return dbImpl._sendRequest('POST', params);
            },
            update: function (params) {
                return dbImpl._sendRequest('PUT', params);
            },
            remove: function (params) {
                return dbImpl._sendRequest('DELETE', params);
            }
        };
        Restful_Ex_3.db = new DevExpress.data.CustomStore(dbImpl);
    })(jQuery, DevExpress);

this is my home.js file :

  1. Restful_Ex_3.home = function (params) {

        var viewModel = {
            jsonp: true,
            dSource: new DevExpress.data.DataSource(Restful_Ex_3.db), //
        };

        return viewModel;
    };

and this is my home.dxview file :

  1. <div data-options="dxView : { name: 'home', title: 'Home' } ">
       <div class="home-view" data-options="dxContent : { targetPlaceholder: 'content' } ">

    <div data-bind="dxList: { dataSource: dSource }">
               <div data-options="dxTemplate : { name: 'product' } " >
                   <span data-bind="text: product"></span>
                 <!--  <span data-bind="text: Description"></span> -->
                   <div data-bind="dxButton: {text: 'Edit', clickAction: function(e) { $root.btnEditClick($data.code, $data.product); }}"></div>
                   <div data-bind="dxButton: {text: 'Delete', clickAction: function(e) { $root.btnDeleteClick($data.code);}}"></div>
               </div>

           <div data-bind="dxTextBox: {dataSource: dSource }">
            <span data-bind="text: product"></span>
           </div>

       </div>
    </div>

I need to take the response from the service and populate a listbox ( or anything at this stage ) with the resulting data. I assume the problem is with the service sending me back an octet-stream, which I need to convert into a usable format.


Can anyone help, please? I am quite new to JSON, but I want to learn