【问题标题】:Curl Post request to upload .zip file to Sharepoint returning "Compressed (zipped) folder invalid when downloading将 .zip 文件上传到 Sharepoint 的 Curl Post 请求返回“压缩(压缩)文件夹在下载时无效
【发布时间】:2020-01-09 06:08:51
【问题描述】:

我有一个 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 "接受:/" -H "内容类型:multipart/form-data" -F "file=@Test.zip;type=application/x-zip-compressed"

我希望 sharepoint 上的文件在下载后有效并正确打开,但出现以下错误。

"Windows 无法打开该文件夹。

压缩(压缩)文件夹“C:\Test.zip”无效。'

【问题讨论】:

    标签: rest curl sharepoint upload zip


    【解决方案1】:

    答案在代码中,虽然文件正在发送,但显然没有正确发送导致损坏。

    下面是我添加的那一行。

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-28
      • 2012-01-23
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 2010-09-05
      相关资源
      最近更新 更多