当我调用VSTS API来上传带有特殊字符的文件时,我的文件名被截断,所有特殊字符均被忽略

时间:2019-06-26 11:36:27

标签: java tfs azure-devops azure-devops-rest-api

我正在调用VSTS API来上传带有特殊字符文件名的文件附件。但是文件名被截断,并且从第一个特殊字符开始的所有字符都被截断,例如,如果filename为file2367@#$$$## 那么相应的上传文件为file2367@,其余所有字符均被截断。 下面是我用于上传附件的代码。

public String uploadAttachment(InputStream inputStream, String fileName) throws Exception {

    fileName=URLEncoder.encode(fileName,"UTF-8");
    logger.info("******file name is******* :" + fileName);

    String query = getBaseUrl() + "_apis/wit/attachments?filename=" + fileName;
    HttpPost httpPost = new HttpPost(query);

    httpPost.addHeader("Content-Type", "application/json");
    httpPost.addHeader("Accept", "application/json;api-version=1.0");
    httpPost.setEntity(new InputStreamEntity(inputStream));
    String authHeader = getAuthHeader();
    httpPost.addHeader("Authorization", authHeader);
    httpPost = ProxyConnectionUtility.getInstance().configureProxy(httpPost);
    CloseableHttpResponse response = httpClient.execute(httpPost);

    logger.info("VSTS attachment response:" + response);
    HttpEntity responseEntity = response.getEntity();
    String strResponse = EntityUtils.toString(responseEntity, "UTF-8");
    int iStatusCode = response.getStatusLine().getStatusCode();
    if (iStatusCode != 200 && iStatusCode != 201) {
        throw new Exception("Record could not be updated due to the error: " + strResponse);
    }

    return strResponse;
}

0 个答案:

没有答案