ng-admin
ng-admin copied to clipboard
Get entity ID for File Upload
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.
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 this does not work, I get following error
Error: You must provide a URL property to allow the upload of files.
Is there any plan to support dynamic information provided on .uploadInformation()
?
+1, as right now the file-uploading is useless as there is no way to bind the uploaded image to the entity being edited.
I need this :(
any progress on this? Otherwise uploadInformation just seems pointless for dynamic content!!!!