Guide on sending a sizable item as a string utilizing Axios

In order to efficiently save a large and complex object as a JSON file on the server without needing to map it to an object in C# first, I am facing some challenges. Sometimes, when posting the object as a string, the data gets corrupted leading to errors during transmission.

Prior attempts to use encodeURI and JSON.stringify followed by HttpUtility.UrlDecode in C# have resulted in unwanted side effects like removing pluses within dataurls for image src attributes.

Is there a method to post the object without encountering these issues? Alternatively, is there a way to receive the object in C# as a generic object that can be serialized without the need for mapping it to a class beforehand?

var data = {
    workflowID: workflowToSave.ID,
    jsonWorkflow: JSON.stringify(workflowToSave)
};

vm.axiosPost("/Workflows/Save", data).then((result) => {
    
}) ...

Answer №1

After initially using the btoa method (as mentioned in my previous response), I encountered some minor issues. To overcome these, I transitioned to utilizing base64-js, which resolved all problems seamlessly. The implementation process was easy and uncomplicated.

Answer №2

After some experimentation, I found a method to securely transmit this information using window.btoa().

var data = {
   workflowID: workflowToSave.ID,
   jsonWorkflow: window.btoa(JSON.stringify(workflowToSave))
};

To convert it back in c#, you can use the following code:

var bytes = Convert.FromBase64String(jsonDocument);
jsonDocument = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
jsonDocument = JsonPrettify(jsonDocument);

This allows me to easily save the data to a file without any issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the myriad of possibilities created by combining arrays

I am working on a code snippet that aims to generate an array containing all possible combinations between two or more arrays. However, I am encountering a specific issue. getCombn(arr: string | any[], pre?: string | undefined) { pre = pre || ' &a ...

I am searching for a straightforward Rails sample that incorporates Ajax

Currently, I am on a quest to find a solid demonstration of how AJAX and JSON interact with Rails. I have a Rails application that relies on standard forms and I am looking to enhance it with some ajax functionality. Unfortunately, I haven't come acro ...

Nested objects in Gson are objects that are contained within another

In my current project, I am utilizing a library that includes a class designed to map a JSON message. Gson is being used to serialize the classes into JSON format. Within the message structure, there is a data field that is generic and can contain any type ...

Retrieving attribute of a span element inside a nested div

Newbie to web scraping and facing an issue. I am trying to extract the value of data-value from the span with class "DFlfde SwHCTb". However, I keep getting an undefined return. Can someone point out what error I made in the code below? const axios = requi ...

Incorporating several configuration and variable files into an Ansible playbook

Within my playbook, I am looking to incorporate two separate configuration files - accountinfo.json and settingsinfo.json. Is it possible to call upon multiple config files simultaneously while executing an Ansible playbook? ...

Trouble with Sound during Quickblox Webrtc Audio Calls

I am having an issue with my audio calls. When I make a call to another user, everything seems fine except that I cannot hear any sound when speaking into the microphone. I am only interested in making audio calls. The call is initiated by pressing a butt ...

The marriage of Vue 2.0 and Rails 5: Shifting from Reactive to Declarative Rendering

As I make my way through the Vue guide with a Rails 5 app, I've noticed that although I am able to update my Vue js object, the DOM doesn't behave as described in the Declarative Rendering section. The data and the DOM are supposed to be linke ...

Develop an interactive React sidebar with changing elements

I'm in the process of developing a sidebar for a project, with the goal of making it similar to tools like Confluence. This means that we need the ability to rearrange documents and create subdirectory structures by simply moving the documents, with ...

Unable to establish a connection to the database while running on the local IIS server

I am facing an issue with my asp.net application running on IIS express in visual studio. The application works fine on IIS express, but when I switch it to run on Local IIS, I encounter a database error: System.Data.SqlClient.SqlException: 'A networ ...

Guide on toggling the button by clicking on the icon to turn it on or off

Within my angular application, I have implemented font icons alongside a toggle switch. Initially, the switch is in the ON state. The specific functionality desired is for clicking on an icon to change its color from white to red (this has been achieved) ...

bespoke theme background hue

I currently have material-ui@next installed and I am attempting to customize the background color of the theme. Here is what I have tried: const customizedTheme = createMuiTheme({ palette: createPalette({ type: 'light', primary: purple ...

Efficiently manage large datasets with Vue.js using the expand/collapse list AJAX pattern

Within my vuejs application, there is a page where I aim to showcase a list of clients. When a user expands an individual client row, it should reveal a list of proposals specific to that client. Additionally, there is an expand/collapse functionality for ...

Utilize jQuery append() to create a grid layout using <td> tags

I need to integrate address information from an object into an HTML table using the append() method. The initial HTML table structure is as follows: <table class="shipping_information" border="1"> </table> To achieve this, I place the addre ...

The JQxTreeGrid is displaying properly, however, it is not loading the data from the JSON source

Looking for some assistance with loading Json data into a Jquery grid using jqxTreegrid. Currently, the grid is displaying but not the data. Despite no errors in the debugger, I'm unable to figure out the issue. Any help resolving this matter would be ...

Is it feasible to utilize jQuery without relying on IDs for selection?

I am currently troubleshooting a code snippet in which jQuery seems to be accessing an element by ID even though the element does not actually have an ID assigned. Here is what I have in the markup: @Html.CheckBoxFor(Model => Model.IsEBSToBeCreated, new ...

Is it possible for me to trigger a custom event using an eventBus listener?

In the Vue component, I have the following setup: data: function() { return { quotes: [] }; }, created() { eventBus.$on("quoteWasAdded", message => { this.quotes.push(message); this.$emit("quotesWereUpdated", this.quot ...

Iterate through each row in a table to locate a particular control by its ID and retrieve its

Is there a way to write a jQuery function that can loop through table rows and find hidden field values based on a specific hidden control ID ("hdnIsEmpty") without affecting other hidden controls? I'm facing this challenge and need help with finding ...

Creating an executable JAR for your Next.js application: A step-by-step guide

Is there a way to ensure that my Next.js file can run seamlessly on any computer without the need for reinstallation of all modules? In my folder, nextjs-node, I have the following subfolders: components lib public node_modules page style package.json I ...

Leveraging HTML5 file uploads alongside AJAX and jQuery

While there are questions with similar themes on Stack Overflow, none seem to quite fit the bill for what I am looking for. Here's my goal: Upload an entire form of data, including a single file Utilize Codeigniter's file upload library So fa ...

javascript Try again with async await

I am working with multiple asynchronous functions that send requests to a server. If an error occurs, they catch it and retry the function. These functions depend on data from the previous one, so they need to be executed sequentially. The issue I am facin ...