0

I Use the smart ng-admin for my website administration.

On the edit view, I display, say a post. On the other hand, I Want to upload an image for that post. My back api needs the information about my post.id , so , post is the model in ng-admin, I want to know how to acces my post id , to do something like that in my view :

nga.field('postImage','file').uploadInformation(
    { 
        'url': settings.baseUrl + 'url/to/upload?ref_id='+ post.id ??? 
    })

Thanks in advance for your help. Have a nice day coding and doing some nice stuffs.

user2626210
  • 115
  • 5
  • 13

1 Answers1

0

I'm doing image uploading slightly differently, but I think it would also work for you. I've built a generic handler that receives the image, then worries about associating the image with the object when the user clicks save.

Your version would work like this: When you upload an image, ng-admin send a request to your base url. Your handler could process the image, upload it to storage, whatever you need to do, and then send back a link to the image.

func upload()
    processPhoto
    return link

The link would then get associated with the post model in ng-admin as the property postImage automatically. When the user clicks Save, another request, which has all the fields you specify in editionView is sent back to the server.

PUT: baseUrl/to/upload
Request Payload
{
    id: 123456
    postImage: link
    ...
}

A different handler could then do whatever processing is needed to permanently associate the image specified in the link to the post object in your DB.

cfatt10
  • 688
  • 1
  • 7
  • 13