本文主要是介绍Jira插件开发中的附件上传,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
介绍一下附件上传的操作,内容是这样,通过一个自定义Action,上传附件同时根据在Action的动作里面创建一个Issue,然后附件挂到该Issue上去
test.vm
- <form enctype="multipart/form-data" action="$requestContext.baseUrl/secure/TestAction.jspa" method="post">
- <input type="file" name="file" >
- <input type="submit">
- </form>
TestAction.java
- @Override
- protected String doExecute() throws Exception {
- MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) ServletActionContext.getRequest();
- File f = wrapper.getFile("file"); //表单中的name
- IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
- issueInputParameters.setProjectId(10000l).setIssueTypeId("1").setSummary("测试附件").setReporterId("admin").setAssigneeId("admin");
- IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(this.getLoggedInUser(), issueInputParameters);
- if (createValidationResult.isValid()) {
- IssueService.IssueResult createResult = issueService.create(getLoggedInUser(), createValidationResult);
- MutableIssue mutableIssue = createResult.getIssue();
- attachmentManager.createAttachment(f, wrapper.getFilesystemName("file"), wrapper.getContentType("file"), getLoggedInUser(), mutableIssue);
- }
- return SUCCESS;
- }
对于文件上传的表单需要这样处理
- MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) ServletActionContext.getRequest();
- //得到要上传的文件对象
- wrapper.getFile("file");
- //取得文件名称
- wrapper.getFilesystemName("file");
- //取得文件类型
- wrapper.getContentType("file");
- ChangeItemBean createAttachment(File file, String filename, String contentType, User author, Issue issue) throws AttachmentException;
这篇关于Jira插件开发中的附件上传的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!