Damage to docx file using byte stream and Dropbox API

We have a web application that allows users to upload files to their Dropbox account. This web application uses the Dropbox API to facilitate the download process. After loading, when the user tries to view the type of the .docx file, he displays a message: "The file" somefile.docx "cannot be opened because there are problems with the content."

Here is the code we use:

First, we convert the file to byte [] and pass it into an API method call.

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

Reply from api {"Winner!" } We also checked that byte [] was not corrupted before it was sent to Dropbox.

Then, when a user tries to open a file by downloading it from a website or simply viewing the file directly from the Dropbox folder, he will receive this error message. enter image description here

This also happens for .xlsx files (Excel 2007). Are .docx and .xlsx files damaged when they are uploaded to the Dropbox API Dropbox folder? Any help was greatly appreciated.

+6
source share
1 answer
Files

.docx and other Office 2007 file types have this problem online. Have you checked your MIME server types (editing - if it uses your server as an intermediate)?

0
source

Source: https://habr.com/ru/post/900242/


All Articles