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