org.kohsuke.stapler.StaplerRequest.getFileItem()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中org.kohsuke.stapler.StaplerRequest.getFileItem()方法的一些代码示例,展示了StaplerRequest.getFileItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StaplerRequest.getFileItem()方法的具体详情如下:
包路径:org.kohsuke.stapler.StaplerRequest
类名称:StaplerRequest
方法名:getFileItem

StaplerRequest.getFileItem介绍

[英]Obtains a commons-fileupload object that represents an uploaded file.
[中]获取表示已上载文件的commons fileupload对象。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override
public ParameterValue createValue(StaplerRequest req) {
  FileItem src;
  try {
    src = req.getFileItem( getName() );
  } catch (ServletException | IOException e) {
    // Not sure what to do here. We might want to raise this
    // but that would involve changing the throws for this call
    return null;
  }
  if ( src == null ) {
    // the requested file parameter wasn't uploaded
    return null;
  }
  FileParameterValue p = new FileParameterValue(getName(), src, getFileName(src.getName()));
  p.setDescription(getDescription());
  p.setLocation(getName());
  return p;
}

代码示例来源:origin: jenkinsci/jclouds-plugin

private static String getJsonString(final String fileUploadEntry, final String fieldName) {
  if (null != fileUploadEntry) {
    try {
      final FileItem fi = Stapler.getCurrentRequest().getFileItem(fileUploadEntry);
      if (null != fi) {
        final String content = new String(fi.get(), StandardCharsets.UTF_8);
        if (null != content && !content.isEmpty()) {
          final JsonObject jo = new JsonParser().parse(content).getAsJsonObject();
          final String value = jo.get(fieldName).getAsString();
          return value;
        }
      }
    } catch (Exception x) {
      LOGGER.warning(x.getMessage());
    }
  }
  return null;
}

代码示例来源:origin: stapler/stapler

public FileItem convert(Class type, Object value) {
    if(value==null) return null;
    try {
      return Stapler.getCurrentRequest().getFileItem(value.toString());
    } catch (ServletException e) {
      throw new ConversionException(e);
    } catch (IOException e) {
      throw new ConversionException(e);
    }
  }
}, FileItem.class);

代码示例来源:origin: org.kohsuke.stapler/stapler

public FileItem convert(Class type, Object value) {
    if(value==null) return null;
    try {
      return Stapler.getCurrentRequest().getFileItem(value.toString());
    } catch (ServletException e) {
      throw new ConversionException(e);
    } catch (IOException e) {
      throw new ConversionException(e);
    }
  }
}, FileItem.class);

代码示例来源:origin: org.hudsonci.stapler/stapler-core

public FileItem convert(Class type, Object value) {
    if(value==null) return null;
    try {
      return Stapler.getCurrentRequest().getFileItem(value.toString());
    } catch (ServletException e) {
      throw new ConversionException(e);
    } catch (IOException e) {
      throw new ConversionException(e);
    }
  }
}, FileItem.class);

代码示例来源:origin: org.jenkins-ci.plugins/scriptler

/**
 * Uploads a script and stores it with the given filename to the configuration. It will be stored on the filessytem.
 * 
 * @param req
 *            request
 * @return forward to index page.
 * @throws IOException
 * @throws ServletException
 */
public HttpResponse doUploadScript(StaplerRequest req) throws IOException, ServletException {
  checkPermission(Hudson.ADMINISTER);
  try {
    
    FileItem fileItem = req.getFileItem("file");
    boolean nonAdministerUsing = req.getSubmittedForm().getBoolean("nonAdministerUsing");
    String fileName = Util.getFileName(fileItem.getName());
    if (StringUtils.isEmpty(fileName)) {
      return new HttpRedirect(".");
    }
    saveScript(fileItem, nonAdministerUsing, fileName);
    return new HttpRedirect("index");
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {
    throw new ServletException(e);
  }
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

/**
   * Performs the actual upload.
   *
   * @param req the request.
   * @return the response.
   * @throws ServletException if something goes wrong.
   * @throws IOException      if something goes wrong.
   */
  @NonNull
  public HttpResponse doUpload(@NonNull StaplerRequest req) throws ServletException, IOException {
    FileItem file = req.getFileItem("certificate.file");
    if (file == null) {
      throw new ServletException("no file upload");
    }
    // Here is the trick, if we have a successful upload we replace ourselves in the stapler view
    // with an instance that has the uploaded content and request stapler to render the "complete"
    // view for that instance. The "complete" view can then do the injection and close itself so that
    // the user experience is the pop-up then click upload and finally we inject back in the content to
    // the form.
    SecretBytes uploadedKeystore = SecretBytes.fromBytes(file.get());
    return HttpResponses.forwardToView(
        new Upload(getDivId(), uploadedKeystore), "complete");
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
public ParameterValue createValue(StaplerRequest req) {
  FileItem src;
  try {
    src = req.getFileItem( getName() );
  } catch (ServletException | IOException e) {
    // Not sure what to do here. We might want to raise this
    // but that would involve changing the throws for this call
    return null;
  }
  if ( src == null ) {
    // the requested file parameter wasn't uploaded
    return null;
  }
  FileParameterValue p = new FileParameterValue(getName(), src, getFileName(src.getName()));
  p.setDescription(getDescription());
  p.setLocation(getName());
  return p;
}

代码示例来源:origin: jenkinsci/credentials-plugin

/**
   * Performs the actual upload.
   *
   * @param req the request.
   * @return the response.
   * @throws ServletException if something goes wrong.
   * @throws IOException      if something goes wrong.
   */
  @NonNull
  public HttpResponse doUpload(@NonNull StaplerRequest req) throws ServletException, IOException {
    FileItem file = req.getFileItem("certificate.file");
    if (file == null) {
      throw new ServletException("no file upload");
    }
    // Here is the trick, if we have a successful upload we replace ourselves in the stapler view
    // with an instance that has the uploaded content and request stapler to render the "complete"
    // view for that instance. The "complete" view can then do the injection and close itself so that
    // the user experience is the pop-up then click upload and finally we inject back in the content to
    // the form.
    SecretBytes uploadedKeystore = SecretBytes.fromBytes(file.get());
    return HttpResponses.forwardToView(
        new Upload(getDivId(), uploadedKeystore), "complete");
  }
}

相关文章

微信公众号

最新文章

更多

StaplerRequest类方法