Bv202 Bv202 - 1 year ago 51
Javascript Question

Long value in object field not sent though REST

I have an object with a

field. This field contains a very long string (base64). When using
, the field seems to contain the string, however, when just printing out this one field, I just get an empty string:

enter image description here

I'm trying to send this object through a REST service, but it just sends the empty string instead of the correct value.

What is going on here? I've used these kind of strings before and it worked fine, but now it looks like I'm missing something important.

To make it clear, this gets the above output:


This prints an empty string:


This is how the
is assigned:

for (var i = 0; i <; i++) {
(function (i) {
var setting = { return setting.Id ==[i].Id });

if (setting[0].Type == 2 &&[i].copiedValue && typeof([i].copiedValue) == 'object') {
.then(function(response) {
var splitted = response.split(",");[i].Value = splitted[1];


.then(function(response) {
vm.success = true;

Answer Source

Upload() is asynchronous so you need all the Upload to complete before you send your final data since that data is dependent on responses from uploads.

You can create array of upload promises and use $q.all() to run code when all of those promises have resolved

Create empty array before the loop and push each upload promise into that array

var uploadPromises = []

Then change

                .then(function(response) {
                   // do stuff with response


var req =  Upload.base64DataUrl([i].copiedValue)
                .then(function(response) {
                   // do stuff with response

Now wrap your final request

$q.all(uploadPromises ).then(function(){    
   // do something when any upload promise is rejected

Note you will need to determine strategy if any upload promise gets rejected. You can use a catch on upload promises themselves to also resolve that promise if that's what you want to do so final request will always be made

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download