小编Som*_*ame的帖子

尝试使用angularJS和c#webapi从服务器下载文件

将文件上传到服务器时,它很棒; 没有损坏的文件.然而,当我下载文件时(除了纯粹的txt:s,它们是woork),它们的大小会变大并变得腐败.经过大量的调查后,我不知道会出现什么问题.我只是将文件作为流写入响应并下载blob.
欢迎任何想法!

严重依赖此Thread解决方案; 使用AngularJS从ASP.NET Web API方法下载文件

现行守则如下;

的WebAPI:

    [Route("GetFile")]
public HttpResponseMessage GetFile()
{
    HttpResponseMessage result = null;
    //Get file object here
    try 
    {
        IEnumerable<string> headerValues = Request.Headers.GetValues("fileID");
        int key = Int32.Parse(headerValues.FirstOrDefault());
        var fetchFile = db.FileRecords.Single(a => a.id == key);

        var localFilePath = fetchFile.path + fetchFile.name;

        if (!System.IO.File.Exists(localFilePath))
        {
            result = Request.CreateResponse(HttpStatusCode.Gone);
        }
        else
        {// serve the file to the client
            //I have used the x-filename header to send the filename. This is a custom header for convenience.
            //You should …
Run Code Online (Sandbox Code Playgroud)

.net c# model-view-controller download angularjs

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

.net ×1

angularjs ×1

c# ×1

download ×1

model-view-controller ×1