首页 / 浏览问题 / 组件GIS / 问题详情
java怎么上传数据到isever服务器上
4EXP 2020年12月17日

想通过restApi上传一直不成功

http://127.0.0.1:8090/iserver/manager/filemanager/uploadtasks/dcc79d2e43a346e4babc27d0fbcbe103_7dde77e3bf624796b91921f9759067f7.rjson?toFile=E:/demo/demo.zip&unzip=true&overwrite=true&token=AygzFzy-jgGn9wnzD5fjHD08GiH6YITYpnIIA74kW4b-OpVFtS3mSUSLalIYfzrWJMTtIa7tik62fhjOzWzWyw..

1个回答

你好,您可以先确认下在快速发布服务的时候,旁边的上传数据是否成功呢,

2,842EXP 2020年12月17日
能正常上传,还有其他可能吗
方便发一下代码吗?我这边测试一下呢
public void test10(){
    RestTemplate restTemplate = new RestTemplate();
    String url = "http://127.0.0.1:8090/iserver/manager/filemanager/uploadtasks/dcc79d2e43a346e4babc27d0fbcbe103_066471d8f9904761b06ab695f91daf1c.rjson?toFile=D:/demo/demo.zip&token=AygzFzy-jgGn9wnzD5fjHD08GiH6YITYpnIIA74kW4b-OpVFtS3mSUSLalIYfzrWJMTtIa7tik62fhjOzWzWyw..";
    HttpHeaders httpHeaders = new HttpHeaders();
    MediaType mediaType = MediaType.parseMediaType("application/json;charset=UTF-8");
    httpHeaders.setContentType(mediaType);
    HttpEntity entity = new HttpEntity(httpHeaders);
    ResponseEntity<Object> exchange = restTemplate.exchange(url, HttpMethod.POST, entity, Object.class);
    System.out.println(exchange.getBody());
}

我直接用Postman生成的资源信息


public void test10(){
    String fileMd5 = FileUtil.getFileMd5("D:\\D.zip");

    RestTemplate restTemplate = new RestTemplate();
    String url0 = "http://127.0.0.1:8090/iserver/manager/filemanager/uploadtasks.rjson?token=AygzFzy-jgGn9wnzD5fjHD08GiH6YITYpnIIA74kW4b-OpVFtS3mSUSLalIYfzrWJMTtIa7tik62fhjOzWzWyw..";

    HttpHeaders httpHeaders = new HttpHeaders();
    MediaType mediaType = MediaType.parseMediaType("application/json;charset=UTF-8");
    httpHeaders.setContentType(mediaType);
    Map<String,Object> params = new HashMap();
    params.put("md5",fileMd5);
    params.put("fileSize","4169");
    params.put("path","D:/D.zip");
    HttpEntity entity = new HttpEntity(params,httpHeaders);
    // 创建上传任务
    ResponseEntity<String> exchange1 = restTemplate.exchange(url0, HttpMethod.POST, entity, String.class);
    Map<String,String> sets=  (Map<String,String>) JSONObject.parse(exchange1.getBody());
    String newResourceLocation = sets.get("newResourceLocation");
    System.out.println(newResourceLocation);

    // 上传
    HttpEntity httpEntity = new HttpEntity(httpHeaders);
    String url =newResourceLocation+".rjson?toFile=D:/demo/demo.zip&token=AygzFzy-jgGn9wnzD5fjHD08GiH6YITYpnIIA74kW4b-OpVFtS3mSUSLalIYfzrWJMTtIa7tik62fhjOzWzWyw..";
    ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
    System.out.println(exchange.getBody());
}

就只有上传的时候会报(500 Internal Server Error)

您可以参考 咱们iserver的samples\code\UseJavaAPI\FileUploadSample 这个范例
...