提交 4a24139c authored 作者: Whispa's avatar Whispa

commit

上级 c4d71602
...@@ -14,6 +14,7 @@ import org.springframework.core.io.ClassPathResource; ...@@ -14,6 +14,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -51,7 +52,7 @@ public class ImageSearchController extends Controller { ...@@ -51,7 +52,7 @@ public class ImageSearchController extends Controller {
@GetMapping @GetMapping
public Result main() throws Exception { public Result main(@RequestParam("url") String url) throws Exception {
//authExplicit(); //authExplicit();
try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) { try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {
...@@ -62,7 +63,6 @@ public class ImageSearchController extends Controller { ...@@ -62,7 +63,6 @@ public class ImageSearchController extends Controller {
Path path = Paths.get(fileName); Path path = Paths.get(fileName);
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
String url = "http://img.championat.com/news/big/l/c/ujejn-runi_1439911080563855663.jpg";
byte[] imageBytes = restTemplate.getForObject(url, byte[].class); byte[] imageBytes = restTemplate.getForObject(url, byte[].class);
ByteString imgBytes = ByteString.copyFrom(imageBytes); ByteString imgBytes = ByteString.copyFrom(imageBytes);
...@@ -79,6 +79,7 @@ public class ImageSearchController extends Controller { ...@@ -79,6 +79,7 @@ public class ImageSearchController extends Controller {
List<AnnotateImageResponse> responses = response.getResponsesList(); List<AnnotateImageResponse> responses = response.getResponsesList();
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String,Object>> list = new ArrayList<>();
for (AnnotateImageResponse res : responses) { for (AnnotateImageResponse res : responses) {
if (res.hasError()) { if (res.hasError()) {
System.out.format("Error: %s%n", res.getError().getMessage()); System.out.format("Error: %s%n", res.getError().getMessage());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论