我的windows phone应用要上传音频文件到MVC3 站点,使用Mango的BackgroundTransfer service。
可能可以这么做,
1.map一个路径到controller:
  1. public override void RegisterArea(AreaRegistrationContext context)
  2.         {
  3.             context.MapRoute(
  4.                 "SingleAudioFile",
  5.                 "Api/Audio/Recieve",
  6.                 new { controller = "AudioFiles", action = "Recieve" }
  7.                 );
  8.         }
复制代码
2.在controller里,有个Receive action:
  1. [HttpPost]   
  2. public JsonResult Recieve(byte[] audio)
  3.      {
  4.          // saving and status report logic here
  5.      }
复制代码

我的问题是怎么绑定要上传的文件到Receive Action 的音频字节参数?
这是我上传数据的方法:
  1. BackgroundTransferRequest btr = new BackgroundTransferRequest (new Uri
  2.                  (siteUrl + "Api/Audio/Recieve",UriKind.Absolute));
  3.     btr.TransferPreferences = TransferPreferences.AllowBattery;
  4.     btr.Method = "POST";
  5.     btr.UploadLocation = new Uri("/" + Transfers + "/" + isoAudioFileName, UriKind.Relative);
  6. Microsoft.Phone.BackgroundTransfer.BackgroundTransferService.Add(btr);
复制代码
实习工程师 2# ming2ming 发表于 2012-2-23 10:56:46
  1. public class BTModelBinder : IModelBinder
  2. {
  3.     public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
  4.     {
  5.         using (var ms = new MemoryStream())
  6.         {
  7.             controllerContext.HttpContext.Request.InputStream.CopyTo(ms);
  8.             return ms.GetBuffer();
  9.         }
  10.     }
  11. }
  12. [HttpPost]
  13. public ActionResult Receive([ModelBinder(typeof(BTModelBinder))] byte[] audio)
  14. {
  15.     ...
  16. }
复制代码
您需要登录后才可以回帖 登录 | 注册

关于我们|手机版|Archiver|DEVDIV.COM ( 京ICP备07040843号 )  

GMT+8, 2012-5-19 17:06

Powered by DEVDIV.COM!

© 2010-2012 DEVDIV.COM Coummunity.

回顶部