Thanks for the adjustments.  A few points:

- I don't think this should go into `DocumentEditForm`, but into `FileEditForm`.  (`ImageEditForm` inherits from that.)  Not sure why this is working for you at all.
- In those two forms, we can expect the context to have a `data` attribute.  The `hasattr` is not necessary.  Also not exactly sure which type `self.context.data` has so maybe it's better to check for `is not None`.
- You're setting a `file` attribute on the content object, so that `get_appstruct` below can pick it up again.  There's no need to set an attribute on the content object.  `get_appstruct` returns a dict; you can just stick the `file` item in there and it'll have the same effect.