In DefaultTemporaryAttachmentSessionsManager, the session retrieved from the XWikiRequest is null, despite the fact that the current XWikiRequest is cloned by the JobMacro, by XWikiContextCopier, in the following statement:
However, when setting a breakpoint on XWikiContextCopier#L81 and evaluating expressions originalXWikiContext.getRequest().getSession() and clonedXWikiContext.getRequest().getSession(), I noticed that the former returns an object as expected, but not the latter. Which means the JobMacro does not copy the session, which could be a bug of the JobMacro.
This message was sent by Atlassian Jira (v9.3.0#930000-sha1:287aeb6)
If image attachments aren't displayed, see this article.