我是 api 特别是 usergrid 的新手。但是我必须通过代码(Java)测试usergrid。有人可以发布一种使用java客户端将资产(文件)上传到usergrid的方法。
问问题
133 次
1 回答
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-05-12T07:02:33.823 回答