@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; }
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; }
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);
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);
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);
/** * 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); } }
/** * 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"); } }
@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; }
/** * 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"); } }