/** * This constructor allows to use an existing form panel. * * @param type file input to use * @param status Customized status widget to use * @param submitButton Customized button which submits the form * @param form Customized form panel */ public SingleUploader( FileInputType type, IUploadStatus status, Widget submitButton, FormPanel form) { super(type, form); final Uploader thisInstance = this; if (status == null) { status = new BaseUploadStatus(); super.add(status.getWidget()); } super.setStatusWidget(status); this.button = submitButton; if (submitButton != null) { submitButton.addStyleName("submit"); if (submitButton instanceof HasClickHandlers) { ((HasClickHandlers) submitButton) .addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { thisInstance.submit(); } }); } if (submitButton instanceof HasText) { ((HasText) submitButton).setText(I18N_CONSTANTS.uploaderSend()); } // The user could have attached the button anywhere in the page. if (!submitButton.isAttached()) { super.add(submitButton); } } }
/** * The doPost method of the servlet. <br> * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); String param = request.getParameter("action"); Uploader up = new Uploader(request); String path = "upload"; up.setSavePath(path); String[] fileType = {".gif", ".png", ".jpg", ".jpeg", ".bmp"}; up.setAllowFiles(fileType); up.setMaxSize(10000); // 单位KB if (param != null && param.equals("tmpImg")) { try { up.upload(); } catch (Exception e) { e.printStackTrace(); } response .getWriter() .print( "<script>parent.ue_callback('" + up.getUrl() + "','" + up.getState() + "')</script>"); } else { up.uploadBase64("content"); response.getWriter().print("{'url':'" + up.getUrl() + "',state:'" + up.getState() + "'}"); } }
/* (non-Javadoc) * @see gwtupload.client.Uploader#setAutoSubmit(boolean) */ @Override public void setAutoSubmit(boolean b) { if (button != null) { button.setVisible(!b); } super.setAutoSubmit(b); }
/* (non-Javadoc) * @see gwtupload.client.Uploader#onFinishUpload() */ @Override protected void onFinishUpload() { super.onFinishUpload(); if (getStatus() == Status.REPEATED) { getStatusWidget().setError(getI18NConstants().uploaderAlreadyDone()); } getStatusWidget().setStatus(Status.UNINITIALIZED); reuse(); assignNewNameToFileInput(); for (Widget i : formWidgets) { if (i instanceof Hidden) { Hidden h = (Hidden) i; if (h.getValue().startsWith(fileInputPrefix)) { h.setValue(getInputName()); } } } getFileInput().getWidget().setVisible(true); if (button != null) { setEnabledButton(true); button.removeStyleName("changed"); if (!autoSubmit) { button.setVisible(true); } } if (autoSubmit) { getFileInput().setText(i18nStrs.uploaderBrowse()); } }
/* (non-Javadoc) * @see gwtupload.client.Uploader#setI18Constants(gwtupload.client.IUploader.UploaderConstants) */ @Override public void setI18Constants(UploaderConstants strs) { super.setI18Constants(strs); if (button != null && button instanceof HasText) { ((HasText) button).setText(strs.uploaderSend()); } }
@NotNull private String createRemoteFile( @NotNull ObjectId id, @NotNull ObjectLoader loader, @NotNull Uploader uploader) throws IOException { // Create LFS stream. final String hash; final String cached = cacheSha256.get(id.name()); long size = 0; if (cached == null) { final MessageDigest md = createSha256(); try (InputStream istream = loader.openStream()) { byte[] buffer = new byte[0x10000]; while (true) { int read = istream.read(buffer); if (read <= 0) break; md.update(buffer, 0, read); size += read; } } hash = new String(Hex.encodeHex(md.digest(), true)); cacheSha256.put(id.name(), hash); cache.commit(); } else { hash = cached; } uploader.upload(id, new Meta(hash, size)); return hash; }
/* (non-Javadoc) * @see gwtupload.client.Uploader#onStartUpload() */ @Override protected void onStartUpload() { super.onStartUpload(); if (button != null) { setEnabledButton(false); button.removeStyleName("changed"); button.setVisible(false); } getFileInput().getWidget().setVisible(false); }
/* (non-Javadoc) * @see gwtupload.client.Uploader#onChangeInput() */ @Override protected void onChangeInput() { super.onChangeInput(); if (button != null) { button.addStyleName("changed"); if (button instanceof Focusable) { ((Focusable) button).setFocus(true); } } }
public void mousePressed() { // Upload the current camera frame. println("Uploading"); loadPixels(); PImage scrImg = get(0, 0, width, height); // First compress it as a jpeg. byte[] compressedImage = compressImage(scrImg); // Set some meta data. UploadMetaData uploadMetaData = new UploadMetaData(); uploadMetaData.setTitle("Frame " + frameCount + " Uploaded from Processing"); uploadMetaData.setDescription("mouseFound"); uploadMetaData.setPublicFlag(true); // Finally, upload/ try { uploader.upload(compressedImage, uploadMetaData); } catch (Exception e) { println("Upload failed"); } println("Finished uploading"); }
private String upload() throws UploadException, IOException { Uploader uploader = new Uploader(); uploader.setMaxFileSize(MAX_FILE_SIZE); uploader.setName(captchan.tfName.getText()); uploader.setEmail(captchan.tfEmail.getText()); uploader.setSubject(captchan.tfSubject.getText()); uploader.setComment(getComment()); uploader.setChallenge(reChallenges.removeFirst()); uploader.setResponse(reResponses.removeFirst()); uploader.setFile(files[workingOn]); uploader.setPostURL(postURL); uploader.setTopicURL(topicURL); uploader.setThread(captchan.tfThread.getText()); uploader.setUserAgent(userAgent); return uploader.upload(); }
public void clear() { formWidgets.clear(); super.clear(); }
public void add(Widget w, int index) { formWidgets.add(w); super.add(w, index); }
public void add(Widget w) { formWidgets.add(w); super.add(w); }
@Override public void setEnabled(boolean b) { super.setEnabled(b); setEnabledButton(b); }
public void prepare(Map conf) { super.prepare(conf); this.tx = new TransferManager(client); }