Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top