2

I have my Rails backend organized to receive a POST like this in a controller:

{
    "entry": {
        "title": {
        "media": {
              "description": "some text",
              "image": ...image here,
        }
    }
}

I can create the entry by POSTing a json like the above, with a base64 encoded image, but I would like to do this using formData instead (because the image might be large, or might even be a video...). I have tried this using Postman and I can create the entry with parameters as entry[title] etc, but how do I express the image attribute? Is it even possible? I tried entry[media][image]but that did not work (did not seemed right either...)

Is it possible to nest things like this when using formData?

rablentain
  • 6,641
  • 13
  • 50
  • 91
  • I wasn't aware that formData can handle a larger image or video than doing it with the method you already have working. Do you have a source for that? – Adamantish Aug 12 '17 at 19:24
  • I believe base64 encoding is making the media larger, which is what i want to avoid. I am not really sure if it is a good approach to send a mobile recorded video by base64 encoding it, is it? – rablentain Aug 12 '17 at 19:27
  • how about this? https://stackoverflow.com/a/30931100/4887159 – Ray Aug 13 '17 at 04:57
  • No you're right. – Adamantish Aug 13 '17 at 12:04

1 Answers1

0

Sure you can.

Do something like this, depending on what is an array or not:

entry[0].title
entry[0].media.description
entry[0].media.image
Ian
  • 2,898
  • 1
  • 27
  • 29