ng-admin icon indicating copy to clipboard operation
ng-admin copied to clipboard

Get entity ID for File Upload

Open paolodamico opened this issue 8 years ago • 6 comments

Hi!

I'm using the FileField and my upload endpoint is something like this:

http://api.example.com/entity/1/

The problem is that I need to provide the URL when I'm defining the field, without knowing the entity's ID, like this: nga.field('logo', 'file').uploadInformation({ 'url': 'http://api.example.com/entity/ID_HERE/', 'accept': '.svg'})

How can I provide the ID of the current entity to upload the file?

P.S. I only use this field in the editionView, therefore the ID is always available.

paolodamico avatar Jul 04 '16 19:07 paolodamico

Indeed, we should be able to pass a function to uploadInformation, passing it the server response and entry as arguments. This way, you would be able to do something like:

nga.field('logo', 'file')
    .uploadInformation((response, entry) => ({
        url: `http://api.example.com/entity/${entry.id}`,
        accept: 'svg',
    }));

jpetitcolas avatar Oct 03 '16 08:10 jpetitcolas

@jpetitcolas this does not work, I get following error Error: You must provide a URL property to allow the upload of files.

mabbasian avatar Feb 24 '17 19:02 mabbasian

Is there any plan to support dynamic information provided on .uploadInformation()?

brickpop avatar May 04 '17 09:05 brickpop

+1, as right now the file-uploading is useless as there is no way to bind the uploaded image to the entity being edited.

situokko avatar Aug 01 '17 09:08 situokko

I need this :(

nicolasriveiro avatar Oct 05 '17 16:10 nicolasriveiro

any progress on this? Otherwise uploadInformation just seems pointless for dynamic content!!!!

jessequinn avatar Mar 27 '20 22:03 jessequinn