简体   繁体   中英

How to download the file sent in JSON FileContentResult from a web api

I am a getting a FileContentResult from a web API for my desktop application.

{
    "fileContents": "JVBERi0xLjMNCjEgMCBvYmoNNzQ3Ng0KJSVFT0Y=",
    "contentType": "application/octet-stream",
    "fileDownloadName": "",
    "lastModified": null,
    "entityTag": null,
    "enableRangeProcessing": false
}

Need to know how the file can be downloaded?

I tried deserializing using Json.Net but it throws error 'Unknown object type! System.Byte'

Instead of Json.Net I tried with Newtonsoft.Json, with below code I was able to download the file.

Dim fcr As System.Web.Mvc.FileContentResult
fcr = Newtonsoft.Json.JsonConvert.DeserializeObject(Of System.Web.Mvc.FileContentResult)(json_string)
File.WriteAllBytes("e:\test.pdf", fcr.FileContents)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM