com.cloudinary.Url.signed()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(109)

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

Url.signed介绍

暂无

代码示例

代码示例来源:origin: cloudinary/cloudinary_java

@Test
public void testNotSignTheUrlSuffix() {
  Pattern pattern = Pattern.compile("s--[0-9A-Za-z_-]{8}--");
  String url = cloudinary.url().format("jpg").signed(true).generate("test");
  Matcher matcher = pattern.matcher(url);
  matcher.find();
  String expectedSignature = url.substring(matcher.start(), matcher.end());
  String actual = cloudinary.url().format("jpg").privateCdn(true).signed(true).suffix("hello").generate("test");
  assertEquals("http://test123-res.cloudinary.com/images/" + expectedSignature + "/test/hello.jpg", actual);
  url = cloudinary.url().format("jpg").signed(true).transformation(new Transformation().angle(0)).generate("test");
  matcher = pattern.matcher(url);
  matcher.find();
  expectedSignature = url.substring(matcher.start(), matcher.end());
  actual = cloudinary.url().format("jpg").privateCdn(true).signed(true).suffix("hello").transformation(new Transformation().angle(0)).generate("test");
  assertEquals("http://test123-res.cloudinary.com/images/" + expectedSignature + "/a_0/test/hello.jpg", actual);
}

代码示例来源:origin: cloudinary/cloudinary_java

if (signed != null) url.signed(signed.booleanValue());
if (useRootPath != null) url.useRootPath(useRootPath);
if (urlSuffix != null) url.suffix(urlSuffix);

代码示例来源:origin: cloudinary/cloudinary_java

@Test
  public void testUrlInTag() {
    String message = "should add token to an image tag url";
    String url = cloudinary.url().signed(true).resourceType("image").type("authenticated").version("1486020273").imageTag("sample.jpg");
    assertThat(url, Matchers.matchesPattern("<img.*src='http://res.cloudinary.com/test123/image/authenticated/v1486020273/sample.jpg\\?__cld_token__=st=11111111~exp=11111411~hmac=9bd6f41e2a5893da8343dc8eb648de8bf73771993a6d1457d49851250caf3b80.*>"));

  }
}

代码示例来源:origin: cloudinary/cloudinary_java

@Test
public void testSignedUrl() {
  // should correctly sign a url
  String expected = DEFAULT_UPLOAD_PATH + "s--Ai4Znfl3--/c_crop,h_20,w_10/v1234/image.jpg";
  String actual = cloudinary.url().version(1234).transformation(new Transformation().crop("crop").width(10).height(20)).signed(true)
      .generate("image.jpg");
  assertEquals(expected, actual);
  expected = DEFAULT_UPLOAD_PATH + "s----SjmNDA--/v1234/image.jpg";
  actual = cloudinary.url().version(1234).signed(true).generate("image.jpg");
  assertEquals(expected, actual);
  expected = DEFAULT_UPLOAD_PATH + "s--Ai4Znfl3--/c_crop,h_20,w_10/image.jpg";
  actual = cloudinary.url().transformation(new Transformation().crop("crop").width(10).height(20)).signed(true).generate("image.jpg");
  assertEquals(expected, actual);
}

代码示例来源:origin: cloudinary/cloudinary_java

@Test
public void testAuthenticatedUrl() {
  cloudinary.config.privateCdn = true;
  String message = "should add token if authToken is globally set and signed = true";
  String url = cloudinary.url().signed(true).resourceType("image").type("authenticated").version("1486020273").generate("sample.jpg");
  assertEquals(message,"http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3", url);
  message = "should add token for 'public' resource";
  url = cloudinary.url().signed(true).resourceType("image").type("public").version("1486020273").generate("sample.jpg");
  assertEquals(message,"http://test123-res.cloudinary.com/image/public/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=c2b77d9f81be6d89b5d0ebc67b671557e88a40bcf03dd4a6997ff4b994ceb80e", url);
  message = "should not add token if signed is false";
  url = cloudinary.url().resourceType("image").type("authenticated").version("1486020273").generate("sample.jpg");
  assertEquals(message,"http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg", url);
  message = "should not add token if authToken is globally set but null auth token is explicitly set and signed = true";
  url = cloudinary.url().authToken(AuthToken.NULL_AUTH_TOKEN).signed(true).resourceType("image").type("authenticated").version("1486020273").generate("sample.jpg");
  assertEquals(message,"http://test123-res.cloudinary.com/image/authenticated/s--v2fTPYTu--/v1486020273/sample.jpg", url);
  message = "explicit authToken should override global setting";
  url = cloudinary.url().signed(true).authToken(new AuthToken(ALT_KEY).startTime(222222222).duration(100)).resourceType("image").type("authenticated").transformation(new Transformation().crop("scale").width(300)).generate("sample.jpg");
  assertEquals(message,"http://test123-res.cloudinary.com/image/authenticated/c_scale,w_300/sample.jpg?__cld_token__=st=222222222~exp=222222322~hmac=55cfe516530461213fe3b3606014533b1eca8ff60aeab79d1bb84c9322eebc1f", url);
  message = "should compute expiration as start time + duration";
  url = cloudinary.url().signed(true).authToken(new AuthToken().startTime(11111111).duration(300))
      .type("authenticated").version("1486020273").generate("sample.jpg");
  assertEquals(message,"http://test123-res.cloudinary.com/image/authenticated/v1486020273/sample.jpg?__cld_token__=st=11111111~exp=11111411~hmac=8db0d753ee7bbb9e2eaf8698ca3797436ba4c20e31f44527e43b6a6e995cfdb3", url);
}

相关文章