Java将文件上传到api端点

j93

因此,我尝试以二进制格式将文件上传到imgur的终结点api需要将文件映射到image密钥,但是我正在努力弄清楚如何做到这一点。

如何做到这一点?

编辑:我尝试使用这篇文章的摘录,但无法使其正常工作。

深层连结

请尝试上面的示例。这是从visualsearchapi.com祝你好运。

public static String simSearchByImg(File file,int  catid ,String subject,String labeland,String labelor,String labelnot) throws IOException{
        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        String result =null;
        try {
            HttpPost httppost = new HttpPost("http://api0.visualsearchapi.com:8084/vsearchtech/api/v1.0/apisim_search");

            FileBody bin = new FileBody(file);
            StringBody catidBody = new StringBody(catid+"" , ContentType.TEXT_PLAIN);
            StringBody keyBody = new StringBody(APPKEY , ContentType.TEXT_PLAIN);
            StringBody langBody = new StringBody(LANG , ContentType.TEXT_PLAIN);
            StringBody fmtBody = new StringBody(FMT , ContentType.TEXT_PLAIN);
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addPart("apikey", keyBody)
            .addPart("photo", bin)
            .addPart("catid", catidBody)
            .addPart("lang", langBody)
            .addPart("fmt", fmtBody);
            if(subject != null && subject.isEmpty() == false){
                 StringBody subjectBody = new StringBody(subject, Charset.forName("UTF-8"));
                 builder.addPart("subject", subjectBody);
            } 
            if(labeland != null && labeland.isEmpty() == false){
                 StringBody labelandBody = new StringBody(labeland , ContentType.TEXT_PLAIN);
                 builder .addPart("labeland", labelandBody);
            }
            if(labelor != null && labelor.isEmpty() == false){
                 StringBody labelorBody = new StringBody(labelor , ContentType.TEXT_PLAIN);
                 builder .addPart("labelor", labelorBody);
            }
            if(labelnot != null && labelnot.isEmpty() == false){
                 StringBody labelnotBody = new StringBody(labelnot , ContentType.TEXT_PLAIN);
                 builder .addPart("labelnot", labelnotBody);
            }
            HttpEntity reqEntity =  builder.build();
            httppost.setEntity(reqEntity);
            response = httpClient.execute(httppost);
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
               // result = ConvertStreamToString(resEntity.getContent(), "UTF-8");
                String charset = "UTF-8";   
                String content=EntityUtils.toString(response.getEntity(), charset);   
                System.out.println(content);
            }
            EntityUtils.consume(resEntity);
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            response.close();
            httpClient.close();
        }
        return result;
    }

    public static void main(String[] args) {
        try {
            simSearchByImg(new File("/path/dog1.jpg"),0,null,null,null,null);
            /*Above Java request upload an image /path/dog1.jpg, search for 
            visually similar images,by using your apikey, values of other parameters 
            are as default*/
            simSearchByImg(new File("/path/dog1.jpg"),45,"pet","345,356",null,"98")
            /*Above Java request upload an image dog1.jpg, search for visually similar 
            images, by using your apikey, search for similar images with keyword “pet”, 
            image category as 45, and result images have labels 345 and 356, 
            but without label 98.  Values of other parameters are as default*/   
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Guzzle 6将文件上传到API端点

来自分类Dev

如何将文件从ReactJS上传到Express端点

来自分类Dev

将文件上传到Message Bird API

来自分类Dev

如何将文件上传到API

来自分类Dev

从Java端将文件上传到REST,而不是从python上传

来自分类Dev

通过Web API将文件上传到Azure文件存储

来自分类Dev

通过Web API将文件上传到Azure文件存储

来自分类Dev

Java Servlet将文件上传到“网页”文件夹

来自分类Dev

Python Google Drive API,将数据上传到内存中,而不是文件上传到磁盘上?

来自分类Dev

如何使用OneDrive REST API将文件上传到OneDrive?

来自分类Dev

如何通过ActiveResource / REST API将文件上传到Redmine?

来自分类Dev

通过API将文件上传到Google云端硬盘

来自分类Dev

使用R将CSV文件上传到REST API

来自分类Dev

使用Blobstore API将文件上传到Google云存储

来自分类Dev

使用Postman Raw将文件上传到Box API

来自分类Dev

使用REST API将文件上传到Firebase存储

来自分类Dev

Python内存问题将多个文件上传到API

来自分类Dev

使用Microsoft Graph API将文件上传到SharePoint Online

来自分类Dev

使用R将CSV文件上传到REST API

来自分类Dev

如何将文件上传到lambda函数或API网关?

来自分类Dev

无法通过 web-api 将文件上传到 slack

来自分类Dev

使用 Drive API 和 PHP 将文件上传到 Teamdrives

来自分类Dev

将文件上传到前端

来自分类Dev

将文件上传到Django

来自分类Dev

从Java将本地文件上传到Google驱动器

来自分类Dev

将文件上传到Google云存储(JAVA)

来自分类Dev

使用 Java API 将图像上传到 Cloudinary

来自分类Dev

将文件上传到Azure文件存储

来自分类Dev

是否可以使用 nativescript 插件 background-http 将图像文件上传到具有以下特征的端点:

Related 相关文章

  1. 1

    使用Guzzle 6将文件上传到API端点

  2. 2

    如何将文件从ReactJS上传到Express端点

  3. 3

    将文件上传到Message Bird API

  4. 4

    如何将文件上传到API

  5. 5

    从Java端将文件上传到REST,而不是从python上传

  6. 6

    通过Web API将文件上传到Azure文件存储

  7. 7

    通过Web API将文件上传到Azure文件存储

  8. 8

    Java Servlet将文件上传到“网页”文件夹

  9. 9

    Python Google Drive API,将数据上传到内存中,而不是文件上传到磁盘上?

  10. 10

    如何使用OneDrive REST API将文件上传到OneDrive?

  11. 11

    如何通过ActiveResource / REST API将文件上传到Redmine?

  12. 12

    通过API将文件上传到Google云端硬盘

  13. 13

    使用R将CSV文件上传到REST API

  14. 14

    使用Blobstore API将文件上传到Google云存储

  15. 15

    使用Postman Raw将文件上传到Box API

  16. 16

    使用REST API将文件上传到Firebase存储

  17. 17

    Python内存问题将多个文件上传到API

  18. 18

    使用Microsoft Graph API将文件上传到SharePoint Online

  19. 19

    使用R将CSV文件上传到REST API

  20. 20

    如何将文件上传到lambda函数或API网关?

  21. 21

    无法通过 web-api 将文件上传到 slack

  22. 22

    使用 Drive API 和 PHP 将文件上传到 Teamdrives

  23. 23

    将文件上传到前端

  24. 24

    将文件上传到Django

  25. 25

    从Java将本地文件上传到Google驱动器

  26. 26

    将文件上传到Google云存储(JAVA)

  27. 27

    使用 Java API 将图像上传到 Cloudinary

  28. 28

    将文件上传到Azure文件存储

  29. 29

    是否可以使用 nativescript 插件 background-http 将图像文件上传到具有以下特征的端点:

热门标签

归档