Curl Post 请求将 .zip 文件上传到 Sharepoint,返回“下载时压缩(zipped)文件夹无效
Curl Post request to upload .zip file to Sharepoint returning "Compressed (zipped) folder invalid when downloading
我有一个 curl Post 请求,试图将最新文档上传到我们的 Sharepoint。它似乎工作正常,我发送的文件是有效的,并且在发送之前可以正常打开。一旦它到达共享点,文件大小是相同的,但是当我下载时它似乎已损坏并且无法打开。
我试过手动将 zip 文件上传到 Sharepoint,这样效果很好。
我也在互联网上搜索了一些解决问题的方法,但我找不到任何东西。
curl -X POST
"http://12.3.456.78:8080/TEST-2.0/sharepoint?relativePath=Shared%20Documents%2FRelease%20Documents%2Fv1&teamSite=Test"
-H "accept: /" -H "Content-Type: multipart/form-data" -F "file=@Test.zip;type=application/x-zip-compressed"
我希望 Sharepoint 上的文件在下载后有效并正确打开,但我收到以下错误。
"Windows 无法打开文件夹。
压缩文件夹 'C:\Test.zip' 无效。'
答案在代码中,虽然文件正在发送,但显然发送不正确,导致损坏。
我添加的不同之处如下。
post.setEntity( new FileEntity(file) );
我的完整方法可以在下面找到,如果以后有人需要这方面的更多信息,请随时发表评论。
public HttpResponse uploadFile( String teamSite,
String relativePath,
String accessToken,
File file ) throws IOException
{
String fileName = null;
HttpClient client = HttpClientBuilder.create().build();
fileName = file.getName().replaceAll( " ", "%20" );
relativePath = relativePath.replaceAll( " ", "%20" );
teamSite = teamSite.replaceAll( " ", "%20" );
HttpPost post = new HttpPost( URL );
post.setHeader( "Accept", "application/json;odata=verbose" );
post.setHeader( "Authorization", "Bearer " + accessToken );
post.setEntity( new FileEntity(file) ); //This line here
HttpResponse response = client.execute( post );
HttpEntity entity = response.getEntity();
@SuppressWarnings("unused")
String responseString = EntityUtils.toString( entity, "UTF-8" );
return response;
}
我有一个 curl Post 请求,试图将最新文档上传到我们的 Sharepoint。它似乎工作正常,我发送的文件是有效的,并且在发送之前可以正常打开。一旦它到达共享点,文件大小是相同的,但是当我下载时它似乎已损坏并且无法打开。
我试过手动将 zip 文件上传到 Sharepoint,这样效果很好。
我也在互联网上搜索了一些解决问题的方法,但我找不到任何东西。
curl -X POST "http://12.3.456.78:8080/TEST-2.0/sharepoint?relativePath=Shared%20Documents%2FRelease%20Documents%2Fv1&teamSite=Test" -H "accept: /" -H "Content-Type: multipart/form-data" -F "file=@Test.zip;type=application/x-zip-compressed"
我希望 Sharepoint 上的文件在下载后有效并正确打开,但我收到以下错误。
"Windows 无法打开文件夹。
压缩文件夹 'C:\Test.zip' 无效。'
答案在代码中,虽然文件正在发送,但显然发送不正确,导致损坏。
我添加的不同之处如下。
post.setEntity( new FileEntity(file) );
我的完整方法可以在下面找到,如果以后有人需要这方面的更多信息,请随时发表评论。
public HttpResponse uploadFile( String teamSite,
String relativePath,
String accessToken,
File file ) throws IOException
{
String fileName = null;
HttpClient client = HttpClientBuilder.create().build();
fileName = file.getName().replaceAll( " ", "%20" );
relativePath = relativePath.replaceAll( " ", "%20" );
teamSite = teamSite.replaceAll( " ", "%20" );
HttpPost post = new HttpPost( URL );
post.setHeader( "Accept", "application/json;odata=verbose" );
post.setHeader( "Authorization", "Bearer " + accessToken );
post.setEntity( new FileEntity(file) ); //This line here
HttpResponse response = client.execute( post );
HttpEntity entity = response.getEntity();
@SuppressWarnings("unused")
String responseString = EntityUtils.toString( entity, "UTF-8" );
return response;
}