Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA SDK code for file upload

Bhagya k April 24, 2020

Hi Team,

 

Trying to write code to upload files in a particular folder.

Tried below code but it doesn't work as SDK does not support apache dependency and imports as DiskFileItemFactory and ServletFileUpload are part of apache.

 

@Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException {
    response.setContentType("application/json");

    DiskFileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    // maximum request size that we process
    upload.setSizeMax(MAX_FILE_SIZE);

    try {
      // Parse the request to get file items.
      List<FileItem> fileItems = upload.parseRequest(request);
      // Process the uploaded file items
      Iterator<FileItem> i = fileItems.iterator();
      String index = null;
      InputStream fis = null;
      while (i.hasNext()) {
        FileItem fi = i.next();
        if (fi.isFormField() && fi.getFieldName().equals("index")) {
          index = fi.getString();
        } else if (!fi.isFormField() && fi.getFieldName().equals("iconFile")) {
          fis = fi.getInputStream();
        }
      }
      this.indexDAO.setIcon(index, fis);

    } catch (Exception e) {
      LOG.error(ERROR_UPLOADING_FILE, e);
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      PrintWriter out = response.getWriter();
      out.print(Utils.buildErrorResponse(ERROR_UPLOADING_FILE, e));
    }

Need help with a workaround using the wrapper or any other code.

 

Thanks in advance.

0 answers

Suggest an answer

Log in or Sign up to answer