gpt4 book ai didi

api - 使用字节流和 Dropbox API 损坏 docx 文件

转载 作者:行者123 更新时间:2023-12-04 16:12:44 27 4
gpt4 key购买 nike

我们有一个网络应用程序,允许用户将文件上传到他们的 Dropbox 帐户。此网络应用程序使用 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 "";
}
}
来自 api 的响应是
{“赢家!”}
我们还验证了 byte[] 在发送到 Dropbox 之前没有损坏。
然后,当用户尝试通过从网站下载文件或直接从 Dropbox 文件夹查看文件来打开文件时,他们会收到此错误消息。
enter image description here
.xlsx(Excel 2007 - up)文件也会发生这种情况。
.docx 和 .xlsx 类型的文件在通过 Dropbox API 上传到 Dropbox 文件夹时是否已损坏?非常感谢任何帮助。

最佳答案

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

关于api - 使用字节流和 Dropbox API 损坏 docx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7922182/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com