从保管箱获取文件并保存在我的服务器上时遇到问题

本文关键字:服务器 遇到 问题 我的 存在 获取 保管箱 文件 保存 | 更新日期: 2023-09-27 18:33:23

这是我从保管箱中选择文件的java脚本代码,当我尝试使用C#将此文件保存到服务器时,我能够在服务器上看到文件,但它是空的。当我尝试打开文件时,文件给出错误,如"文件已损坏"。 使用信号R。

options = {
    // Required. Called when a user selects an item in the Chooser.
    success: function (files) {
        alert("Here's the file link: " + files[0].link)
        hub.server.servermethod(files[0].link, files[0].name);
    },
    // Optional. Called when the user closes the dialog without selecting a file
    // and does not include any parameters.
    cancel: function () {
    },
    // Optional. "preview" (default) is a preview link to the document for sharing,
    // "direct" is an expiring link to download the contents of the file. For more
    // information about link types, see Link types below.
    linkType: "preview", // or "direct"
    // Optional. A value of false (default) limits selection to a single file, while
    // true enables multiple file selection.
    multiselect: false, // or true
    // Optional. This is a list of file extensions. If specified, the user will
    // only be able to select files with these extensions. You may also specify
    // file types, such as "video" or "images" in the list. For more information,
    // see File types below. By default, all extensions are allowed.
    extensions: ['.csv', '.xls', '.tsv', '.xlsx', '.txt'],
};
var button = Dropbox.createChooseButton(options);
$('#container').append(button);
function some() {
    Dropbox.choose(options);
}

服务器方法代码为

       // execute the request
           HttpWebResponse response = (HttpWebResponse)
               request.GetResponse();
           // we will read data via the response stream
           Stream resStream = response.GetResponseStream();
           string tempString = null;
           int count = 0;
           Byte[] buffer = new Byte[32 * 1024];
           StringBuilder sb = new StringBuilder();
           do
           {
               // fill the buffer with data
               count = resStream.Read(buffer, 0, buffer.Length);
               // make sure we read some data
               if (count != 0)
               {
                   // translate from bytes to ASCII text
                   tempString = Encoding.ASCII.GetString(buffer, 0, count);
                   // continue building the string
                   sb.Append(tempString);
               }
           }
           while (count > 0); // any more data to read?
           using (FileStream fs = File.Create(System.Configuration.ConfigurationManager.AppSettings.GetValues("DocumentPath").First().ToString() + fileName))
           {
               // Byte[] bufer = new Byte[32 * 1024];
               fs.Write(buffer, 0, buffer.Length);
           }

从保管箱获取文件并保存在我的服务器上时遇到问题

您将linkType设置为"预览",这将为您提供指向文件预览页面的链接,而不是文件内容本身。如果您想直接访问文件内容,例如,立即以编程方式将内容下载到您的服务器,就像您似乎正在尝试的那样,您应该使用"直接"linkType