2

I'm using Inkfilepicker.io for picture uploading on a project I'm working on. When you upload a picture, it returns a JavaScript object with some data in it. I need more, though. So I query their API using their SDK to get more. I then add this information to each object. Lastly, I post these objects using jQuery to process it on the backend. However, none of the second batch of information goes along for the ride on the backend. I manually used JSON.stringify() to see what the data looked like before it was posted. The new data was not included.

fp.pickAndStore({multiple: true}, {}, function (InkBlobs)
    {
        InkBlobs = $.map(InkBlobs, function(blobio, index)
        {
            fp.stat(blobio, {
                width: true,
                height: true
            }, function(meta) {
                blobio.width = meta.width;
                blobio.height = meta.height;
            });

            return blobio;
        });
        console.log(InkBlobs);
        console.log(JSON.stringify(InkBlobs));
        $.post('/picture', { blobs: InkBlobs }, function(data)
        {
            console.log(data);
        }, 'json');
    });

How can I make sure all of the attributes get sent?

UPDATE

The string created by the JSON.stringify() looks like the following:

[{"url":"https://www.filepicker.io/api/file/PinzEEUlRhSCpc4dYa0w","filename":"browserWars.jpeg","mimetype":"image/jpeg","size":34284,"key":"Vx1xEuqHTKKCM4hjR6LL_browserWars.jpeg","container":"kandidlypictures","isWriteable":true},{"url":"https://www.filepicker.io/api/file/wdnWcCUWStiBxbrONeSN","filename":"1440-music-is-the-food.jpg","mimetype":"image/jpeg","size":97814,"key":"0RrSFSQBTCiifZ8ZkuIj_1440-music-is-the-food.jpg","container":"kandidlypictures","isWriteable":true},{"url":"https://www.filepicker.io/api/file/trdKhlORPCJEu3JRbPYf","filename":"any_browser.jpeg","mimetype":"image/jpeg","size":271194,"key":"1aJNE9MSEyEiAJZAacfD_any_browser.jpeg","container":"kandidlypictures","isWriteable":true}]

The expected output should also include a width and height for each object.

searsaw
  • 3,492
  • 24
  • 31
  • Can you show expected and current outputs? – roydukkey Jan 22 '14 at 04:00
  • jQuery does not call `JSON.stringify` on you `InkBlobs` given as data to the `post()` call, did you expect that? – Bergi Jan 22 '14 at 04:19
  • What exactly does `InkBlobs` contain? Notice that not all JS data types can be `JSON.stringify`ed, I'm not sure of `Blob`s… – Bergi Jan 22 '14 at 04:22
  • Yes, Bergi, I did expect it to use `stringify()`. Even if it doesn't though, it still isn't posting the full object to the backend. It sends exactly what `stringify()` creates, which is shown above. – searsaw Jan 22 '14 at 23:29

1 Answers1

1

Use a separate named function:

var data = {
           width: true,
           height: true
           };

var fn = function fn(meta)
  {
  blobio.width = meta.width;
  blobio.height = meta.height;

  $.post('/picture', { blobs: InkBlobs }, function(data)
    {
    console.log(data);
    }, 'json');
  };

fp.statSync(blobio, data, fn)

Or use statSync since stat is asynchronous:

fp.statSync(blobio, {
                width: true,
                height: true
            }, function(meta) {
                blobio.width = meta.width;
                blobio.height = meta.height;
            });

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265