Confluecne 8 compatibility issue (upload attachment)

Hi,
I can not get files from request in Confluence 8.
Is this related to Confluecne 8 being upgraded to struts2?
I don’t know how to solve it in the code below.

atlassian-plugin.xml:

<servlet-filter name="FileUpload Servlet Filter" i18n-name-key="xxxxx.name" key="xxxxx"
                class="com.xxx.plugin.xxx.filter.FileUploadFilter" location="before-dispatch"
                weight="100">
    <url-pattern>*drag-and-drop*</url-pattern>
    <url-pattern>*upload.action*</url-pattern>
    <url-pattern>*/pages/plugins/attachments/doattachfile.action*</url-pattern>
     ...
</servlet-filter>

java code:

public class FileUploadFilter implements Filter {
 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
  if (requestURI.endsWith("/pages/plugins/attachments/doattachfile.action")) {    // attachment macro select a file then upload 
      HttpServletRequest request = (HttpServletRequest) servletRequest;
      AttachmentRequestWrapper attachmentRequestWrapper = new AttachmentRequestWrapper(request);

      DiskFileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
      // get files from request
      List<FileItem> fileItems = upload.parseRequest(request);  // Confluence 8: fileTtems.size = 0    Confluence 7 works fine: fileTtems.size != 0
  } 
 }
}
3 Likes

Hello,
After updating the Confluence 8 version,
It’s going through the same phenomenon. Have you solved the problem? If you solved it, please share it.
Thank you.

Hi, XingGuo

I also work well on the 7th version of Confluence, but I’m experiencing the same issue on the 8th version.

List<FileItem> fileItems = upload.parseRequest(req);

fileItems is []

Did you solve this problem?

Hello,
After updating the Confluence 8 version,
It’s going through the same phenomenon. Have you solved the problem? If you solved it, please share it.
Thank you.

Hi all,

Multipart requests are parsed differently in different versions of Confluence. Please refer to the following utility class for how to retrieve a file upload. There are also a number of convenience methods that should prevent you having to write any retrieval code yourself.

com.atlassian.xwork.FileUploadUtils