当前位置: 首页>>代码示例>>Java>>正文


Java RoutingContext.fileUploads方法代码示例

本文整理汇总了Java中io.vertx.ext.web.RoutingContext.fileUploads方法的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext.fileUploads方法的具体用法?Java RoutingContext.fileUploads怎么用?Java RoutingContext.fileUploads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.ext.web.RoutingContext的用法示例。


在下文中一共展示了RoutingContext.fileUploads方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx) {
	String encryptedId = UserManager.getEncryptedIdFromSession(ctx);
	new File("profile-images/" + encryptedId + ".png").delete();
	// Refresh
	
	Set<FileUpload> files = ctx.fileUploads();
	
	for(FileUpload file : files) {
		File uploadedFile = new File(file.uploadedFileName());
		uploadedFile.renameTo(new File("profile-images/" + encryptedId + ".png"));
		try {
			uploadedFile.createNewFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
		new File(file.uploadedFileName()).delete();
	}
	
	ctx.response().setStatusCode(201).end();
	ctx.response().close();
}
 
开发者ID:JoMingyu,项目名称:Daejeon-People,代码行数:23,代码来源:SetProfileImage.java

示例2: BHandler

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
BHandler(RoutingContext context) {
  this.context = context;
  Set<FileUpload> fileUploads = context.fileUploads();

  final String contentType = context.request().getHeader(HttpHeaders.CONTENT_TYPE);
  if (contentType == null) {
    isMultipart = false;
    isUrlEncoded = false;
  } else {
    final String lowerCaseContentType = contentType.toLowerCase();
    isMultipart = lowerCaseContentType.startsWith(HttpHeaderValues.MULTIPART_FORM_DATA.toString());
    isUrlEncoded = lowerCaseContentType.startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString());
  }

  if (isMultipart || isUrlEncoded) {
    makeUploadDir(context.vertx().fileSystem());
    context.request().setExpectMultipart(true);
    context.request().uploadHandler(upload -> {
      // *** cse begin ***
      if (uploadsDir == null) {
        failed = true;
        CommonExceptionData data = new CommonExceptionData("not support file upload.");
        throw new ErrorDataDecoderException(ExceptionFactory.createConsumerException(data));
      }
      // *** cse end ***

      // we actually upload to a file with a generated filename
      uploadCount.incrementAndGet();
      String uploadedFileName = new File(uploadsDir, UUID.randomUUID().toString()).getPath();
      upload.streamToFileSystem(uploadedFileName);
      FileUploadImpl fileUpload = new FileUploadImpl(uploadedFileName, upload);
      fileUploads.add(fileUpload);
      upload.exceptionHandler(context::fail);
      upload.endHandler(v -> uploadEnded());
    });
  }
  context.request().exceptionHandler(context::fail);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:39,代码来源:RestBodyHandler.java

示例3: updateWechatPaySetting

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void updateWechatPaySetting(RoutingContext rc) {
    if (forbidAccess(rc, "uid", true)) {
        return;
    }
    Set<FileUpload> uploads = rc.fileUploads();
    HttpServerRequest req = rc.request();
    HttpServerResponse resp = rc.response().putHeader("content-type", "application/json; charset=utf-8");
    //解析参数
    Long uid = Long.parseLong(req.getParam("uid"));
    Integer paySwitch = Integer.parseInt(req.getParam("paySwitch"));
    String mchId = req.getParam("mchId");
    String payKey = req.getParam("payKey");

    //参数检查
    if (paySwitch == 1 && !CommonUtils.notEmptyString(mchId, payKey)) {
        resp.end(new JsonObject().put("status", "invalid").toString());
        return;
    }

    // 异步保存证书文件
    if (uploads != null && !uploads.isEmpty()) {
        for (FileUpload next : uploads) {
            if (paySwitch == 1 && "cert".equals(next.name()) && next.size() > 0) {
                String filePath = Constants.CERT_DIR + uid + "_wxPay.p12";
                FileSystem fs = this.vertx.fileSystem();
                fs.exists(filePath, ex -> {
                    if(ex.succeeded()){
                        Future<Void> delFuture = Future.future();
                        Future<Void> copyFuture = Future.future();
                        fs.delete(filePath, delFuture.completer());
                        fs.copy(next.uploadedFileName(), filePath, copyFuture.completer());
                        if(ex.result()){
                            delFuture.compose(res -> {}, copyFuture);
                        }
                        copyFuture.setHandler(res -> {
                            if (res.succeeded()) {
                                log.info("复制文件{}到{}成功!", next.uploadedFileName(), filePath);
                            } else {
                                log.error("复制文件" + next.uploadedFileName() + "到" + filePath + "失败!", res.cause());
                            }
                        });
                    } else {
                        log.error("判断文件" + filePath + "是否存在时抛出异常!", ex.cause());
                    }
                });
                break;
            }
        }
    }

    //保存支付参数
    JsonObject acc = new JsonObject().put(ID, uid).put(MCHID, mchId).put(MCHKEY, payKey).put(WXPAYON, paySwitch);
    updatePaySetting(resp, acc, COMMAND_UPDATE_WECHATPAY);
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:55,代码来源:PaySettingSubRouter.java

示例4: ingest

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public Epsilon<T> ingest(final RoutingContext context,
                         final Epsilon<T> income)
        throws WebException {
    Object returnValue = null;
    final Class<?> paramType = income.getArgType();
    if (is(Session.class, paramType)) {
        // Session Object
        returnValue = context.session();
    } else if (is(HttpServerRequest.class, paramType)) {
        // Request Object
        returnValue = context.request();
    } else if (is(HttpServerResponse.class, paramType)) {
        // Response Object
        returnValue = context.response();
    } else if (is(Vertx.class, paramType)) {
        // Vertx Object
        returnValue = context.vertx();
    } else if (is(EventBus.class, paramType)) {
        // Eventbus Object
        returnValue = context.vertx().eventBus();
    } else if (is(User.class, paramType)) {
        // User Objbect
        returnValue = context.user();
    } else if (is(Set.class, paramType)) {
        // FileUpload
        final Class<?> type = paramType.getComponentType();
        if (is(FileUpload.class, type)) {
            returnValue = context.fileUploads();
        }
    } else if (is(JsonArray.class, paramType)) {
        // JsonArray
        returnValue = context.getBodyAsJsonArray();
    } else if (is(JsonObject.class, paramType)) {
        // JsonObject
        returnValue = context.getBodyAsJson();
    } else if (is(Buffer.class, paramType)) {
        // Buffer
        returnValue = context.getBody();
    }
    return null == returnValue ? income.setValue(null) : income.setValue((T) returnValue);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:43,代码来源:TypedAtomic.java


注:本文中的io.vertx.ext.web.RoutingContext.fileUploads方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。