使用Java将zip文件上传到ckan

问题描述 投票:0回答:0

我有一个工作的Java应用程序,使用此代码将文本文件上传到ckan安装。

File file = new File("path/testFile.txt")
ContentBody cbFile = new FileBody(file ,ContentType.TEXT_HTML);
HttpEntity reqEntity = MultipartEntityBuilder.create()
           .addPart("file", cbFile) 
           .build();
postRequest = new HttpPost(HOST+"/api/action/resource_create");
postRequest.setEntity(reqEntity);
postRequest.setHeader("X-CKAN-API-Key", myApiKey);         
HttpResponse response = httpclient.execute(postRequest);

当我尝试将文本文件更改为zip文件时,出现500错误“服务器错误”

我猜这是因为ContentType 。 我试图找到替代方法,但似乎无济于事。 试图像这样创建自己的

ContentType zipType=ContentType.create("application/zip");
ContentBody cbFile = new FileBody(file ,zipType);

但仍然没有工作。

有任何想法吗?

更新
似乎文件大小有问题。 我的程序适用于小型zip文件(<5KB)。 我不确定这是java还是ckan问题。 有什么帮助吗?

java content-type ckan
© www.soinside.com 2019 - 2024. All rights reserved.