when I use the Request.InputStream in MVC3 action method to save the file sent by action script I got a corrupted file. When I used firebug to trace the request I realized that the Content-type is "application/x-amf" and has the file name at the end of the stream. knowing that I can't change the action script I need a way to save the file correctly to disk.
how can asp.net mvc3 receive mp3 file sent by flash (application/x-amf)
381 Views Asked by Maged Farag At
2
There are 2 best solutions below
2

You may be able to handle it the same way that I do in the VoiceModel project when an IVR sends an audio file in a POST. Here is the code used in the controller.
[HttpPost]
public ActionResult SaveRecording(HttpPostedFileBase CallersMessage)
{
if (CallersMessage != null && CallersMessage.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(CallersMessage.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath(recordingPath), fileName);
CallersMessage.SaveAs(path);
}
string vm_id = Request.QueryString["vm_id"];
string vm_event = Request.QueryString["vm_event"];
string vm_result = "";
return VoiceView(vm_id, vm_event, vm_result);
}
VoiceModel is an open source project and you can download the code and examples on CodePlex. The "Recording Example" shows how to use this feature.
Just to save time I encoded the byte array into base64 string and sent it to server. Then decoded it on the server side and saved the file. It works fine for now.