Manipulating data with Angular's array object

I am having an issue with posting an object array. I anticipate the post to be in JSON format like this:

{"campaign":"ben",
"slots":[
      {                        
     "base_image": "base64 code here"
      }
       ]
}

However, when I attempt to post, I receive this error in the console:

angular.js:9866 POST /ccuploader/Campaign/updateSlots 413 (Payload Too Large) (anonymous) @ angular.js:9866 n @ angular.js:9667 f @ angular.js:9383 (anonymous) @ angular.js:13248 $eval @ angular.js:14466 $digest @ angular.js:14282 $apply @ angular.js:14571 (anonymous) @ angular.js:21571 dispatch @ jquery.min.js:3 r.handle @ jquery.min.js:3 app.js:71 failed

I am unsure of why my post is not successful. Could someone please help me identify my mistake?

This is my JavaScript code:

 $scope.SaveImage = function () {
        $http({
            url: "http://www.somesite.co.uk/ccuploader/Campaign/updateSlots",
            method: "POST",
            data: $.param({ 'campaign': "name", 'slots': $scope.slots }),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function (response) {
            // success
            console.log('success');
            console.log("then : " + JSON.stringify(response));
        }, function (response) { // optional
            // failed
            console.log('failed');
            console.log(JSON.stringify(response));
        });
    };

Answer №1

It appears that you are transmitting a base64 encoded string using the POST request. Most web servers impose a limit on the size of POST data. To avoid issues, ensure your server is configured to allow large POST parameters. The implementation may vary depending on the server.

If you are working with a PHP server, you can refer to this guide:
Increasing the maximum post size

For uploading images, consider chunking them instead of sending all at once. There are libraries available for this purpose to prevent browser hang and request timeout, known as multipart upload.

You can successfully upload large amounts of image data using the multipart upload mechanism without any issues.

UPDATE

When sending heavy payloads, avoid using the $.param function to directly pass parameters to the data object. Using $.param might lead to exceptions during request parsing due to the heavy payload.

$scope.SaveImage = function () {
        $http({
            url: "http://www.somesite.co.uk/ccuploader/Campaign/updateSlots",
            method: "POST",
            data: { 
                  campaign: "name",
                  slots: $scope.slots
            }),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function (response) {
            // success
            console.log('success');
            console.log("then : " + JSON.stringify(response));
        }, function (response) { // optional
            // failed
            console.log('failed');
            console.log(JSON.stringify(response));
        });

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

What are the best practices for securely storing a distinctive client identifier for websockets?

In order to differentiate and identify the specific client sending a request through web-sockets, I require a unique client identifier. However, I'm uncertain about the optimal method for storing this identifier so that it can be included with every s ...

What are the steps to adjust the size of the Facebook "like" button?

Is there a way to modify the size of the Facebook like button? I attempted to adjust the padding of <a class="connect_widget_like_button clearfix like_button_no_like"> using jQuery, but was unsuccessful. Any suggestions on how this can be achieved? ...

Tips for halting the navigation bar when scrolling

Creating a Navigation Bar: <div class="navigation-bar"> <div class="item">Home</div> <div class="item">About us</div> <div class="item">Our Services</div> <div class="item">Contact us</div ...

The Angular CLI encountered a 404 Not Found error while attempting to load the symbol-observable at http://localhost:4200

Issue encountered after upgrading angular cli to beta 9: Failed to load resource: the server responded with a status of 404 (Not Found) zone.js:461 Unhandled Promise rejection: (SystemJS) Error: XHR error (404 Not Found) loading http://localhost:4200/symb ...

After clicking on the checkbox, req.body.task becomes undefined

Whenever I click on the checkbox, the value of req.body.task returns as undefined. <input type="checkbox" name="task" autocomplete="off" checked="" onchange="onToDochange({{id}})"> This function is triggered by a change event on the checkbox and it ...

Despite containing data, the JSON object continues to display as undefined

I'm encountering an issue with my json data. I'm able to access all the key's values such as ._id and price, but I'm struggling to access retailer and retailer_slug. Despite numerous attempts, I can't seem to figure out what I&apos ...

Attempting to conceal a div element along with its contents using AngularJS

I am attempting to use AngularJS to hide a div and its contents. I have defined a scope variable initialized as false and passed it to the div in order to hide it. However, the div is still visible along with its content. <script type="text/javascr ...

What is the best way to structure a hierarchy in an array or object data using Node.js?

I have the following data arrangement: [{ Country: 'USA', State: 'CA', City: 'LA', District: 'LA-1',Town: 'LA-1,LA-1a,LA_AZ_A',Area: 'Area 51'}, { Country: 'USA', State: 'CA&ap ...

Is there a way to convert the text within a div from Spanish to English using angular.js?

I am working with a div element that receives dynamic text content from a web service in Spanish. I need to translate this content into English. I have looked into translation libraries, but they seem more suited for individual words rather than entire dyn ...

Can jQuery Autocomplete function without stopping at white spaces?

Is there a way to modify jQuery UI autocomplete so that it can handle multiple words instead of terminating with a space? For example, if you input "New York City", it should still filter results based on each word. $.ajax({ type: "GET" ...

Shifting HTML table in Javascript by toggling checkboxes

When I click the checkbox, the table elements are not displaying inline. I am simply hiding the class "box". Do I need to write a special format? By default, the elements are displayed inline but when I check the checkbox, they shift. The column 'Stat ...

Understanding the discrepancy between functional and error when parsing JSON with Pandas

After successfully parsing this JSON data: r='''[{"count":3,"date_time":"2014-08-26T00:00:00","quality_code":0,"value":30},{"count":67,"date_time":"2014-08-27T00:00:00","quality_code":0,"value":32.388059701492537},{"count":72,"date_time":"2 ...

Combining Rails with AngularJS seamlessly

I've spent the last few hours trying to integrate Rails with Angular, following a tutorial that I found. At this point, I'm ready to throw in the towel. The tutorial can be found here. But, I simplified things even more: In my application.js fi ...

Having trouble with publishing to npm as public with the --access flag not functioning properly?

When trying to publish a fresh scoped package on NPM using the command npm publish --access public, I encountered the following error: ole@mki:~/cli$ npm publish --access public npm ERR! publish Failed PUT 403 npm ERR! code E403 npm ERR! F ...

Verify the presence of values in several textarea fields with jQuery before executing a specified action

My main goal is to validate multiple dynamic forms on a single page. If all textareas are either empty or contain default values, I need a specific function to be executed. However, if any of the textareas have content that deviates from the default value, ...

Leveraging Ajax data within a Python script

I'm currently exploring ways to populate a PostgreSQL table using data obtained from an Ajax POST request in Python. The Ajax command I am using is as follows: function ajaxFct() { $.ajax({ async: true, type: "POST", url: ...

Is it possible to utilize the useRef Hook for the purpose of storing and accessing previous state values?

If you have already implemented the useState and useEffect Hooks for maintaining previous state, another approach is to utilize the useRef Hook to track previous state values as well. ...

Transferring a Query between Domains with the Help of JavaScript

It is necessary to develop a function that generates a query based on the user's input of "Test" in an INPUT on Site A (SiteA.com) and then redirects to Site B within the same window, passing along the query (SiteB.com/search.aspx?k=test). Code snipp ...

CSS - using numbers to create dynamic background images

I am looking to create a design where the background images in CSS display increasing numbers per article, like this example: This idea is similar to another post on Stack Overflow discussing using text as background images for CSS. You can find it here: ...

I need to link the click function to the li components within the xpages autocomplete feature

I've successfully implemented Tim Tripcony's advanced type-ahead solution and it's working well. However, I'd like to customize it a bit by redirecting the user to the selected document instead of filling the editbox with the selected d ...