使用字节流和Dropbox API破坏docx文件

Dun*_*Dun 6 api docx xlsx dropbox

我们有一个网络应用程序,允许用户将文件上传到他们的Dropbox帐户.此Web应用程序使用Dropbox API来促进上载过程.上传后,当用户尝试查看文件类型.docx时,它会显示一条消息,"文件"somefile.docx"无法打开,因为内容存在问题".

以下是我们使用的一些代码:

首先,我们将文件转换为byte []并将其传递给API方法调用.

public static string DropboxUpload(byte[] DBbyte, string filename, string token, string tokensecret)
    {
        try
        {
            for (int i = 0; i < 4; i++)
            {
                var dropclient = new RestClient(FILEURL);
                dropclient.ClearHandlers();
                dropclient.AddHandler("*", new JsonDeserializer());

                dropclient.BaseUrl = FILEURL;
                dropclient.Authenticator = new OAuthAuthenticator(dropclient.BaseUrl, API_KEY, API_SECRET, token, tokensecret);

                var request = new RestRequest(Method.POST);
                request.Resource = VERSION + "/files/dropbox" + PATH;
                request.AddParameter("file", filename);

                request.AddFile(new FileParameter { Data = DBbyte, FileName = filename, ParameterName = "file" });

                var response = dropclient.Execute(request);

                if (response.StatusCode == HttpStatusCode.OK)
                    break;
                else
                    Thread.Sleep(1000);   
            }

            string dropboxLink = GetPublicLinks(filename, token, tokensecret);
            dropboxLink = dropboxLink.Replace("\"", "");
            return dropboxLink;
        }
        catch
        {
            return "";
        }
    }
Run Code Online (Sandbox Code Playgroud)

来自api的响应是{"Winner!"}我们还验证了byte []在发送到Dropbox之前没有被破坏.

然后,当用户尝试通过从网站下载文件或直接从Dropbox文件夹中查看文件来打开文件时,他们会收到此错误消息. 在此输入图像描述

这也发生在.xlsx(Excel 2007-up)文件中..docx和.xlsx类型的文件在Dropbox API上传到Dropbox文件夹时会被破坏吗?任何帮助非常感谢.

小智 0

.docx 文件和其他 Office 2007 文件类型在线存在此问题。您是否检查过您的服务器 MIME 类型(编辑 - 如果它使用您的服务器作为中间对象)?