【问题标题】:How to upload an asset to usergrid api using java sdk [closed]如何使用 java sdk 将资产上传到 usergrid api [关闭]
【发布时间】:2016-05-04 09:40:17
【问题描述】:

我是 api 特别是 usergrid 的新手。但是我必须通过代码(Java)测试usergrid。有人可以发布一个使用java客户端将资产(文件)上传到usergrid的方法。

【问题讨论】:

    标签: java usergrid


    【解决方案1】:

    经过一番努力,我找到了一种方法。就是这样..

        public static ApiResponse uploadFileToServer(){
        File file = new File("your asset path");
        Map<String, Object> dataParams = new HashMap<String, Object>();
        data.put("name", <file_name>);
        data.put("file", file);
        //here type and name are necessary to create entity
        data.put("type", <collection_name>);
        data.put("name", <entity_name>);
        //entity_name will be the name of your new created entity.
        Client client = new Client(<organization_name>, <application_name>);
        client.setApiUrl(<url to hit>);
        client.authorizeAppUser(<username>, <password>);
        client.createEntity(dataParams);
        String <uri> = <collection_name> + "/" + <entity_name>;
        ApiResponse response = client.httpRequest(HttpMethod.POST,ApiResponse.class, null, dataParams, <organization_name>, <application_name>,
                <uri>);
        return response;
        }
    

    【讨论】:

    • 您不需要读取序列化文件,因为请求会为您执行此操作。
    猜你喜欢
    • 2016-06-05
    • 2015-05-25
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 2012-09-25
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多