0

したがって、ブロブをサーバーに保存するには、Chrome に記録された WAV ファイルをサーバーに保存することを参照しています。しかし、この PHP 文を C# に翻訳することはできません。

<?php
// get the temporary name that PHP gave to the uploaded file
$tmp_filename=$_FILES["that_random_filename.wav"]["tmp_name"];
// rename the temporary file (because PHP deletes the file as soon as it's done with it)
rename($tmp_filename,"/tmp/uploaded_audio.wav");
?>

これが私がこれまでに試したことです

意見

var fd = new FormData();
fd.append("that_random_filename.wav", blob);
xhr.open("POST", "SubmitSound", true);
xhr.send(fd);

モデルを見る

public class SoundBlob
{        
    public string key { get; set; }
    public HttpPostedFileBase blob { get; set; } // I tried byte[] and string too
}

コントローラ

       [HttpPost]
        public ActionResult SubmitSound(SoundBlob blob)
        {
            // Create the new, empty data file.
            string fileName = AppDomain.CurrentDomain.BaseDirectory + "/Content/Sound/" + Environment.TickCount + ".wav";
            FileStream fs = new FileStream(fileName, FileMode.CreateNew);
            BinaryWriter w = new BinaryWriter(fs);

            blob.blob.SaveAs(blob.key);
            w.Close();
            fs.Close();           
            return new JsonResult() { Data = "Saved successfully" };
        }

keyblobの両方SoundBlobが null です。どうすれば修正できますか?

4

2 に答える 2

1

このスクリプトを使用するのではなく、C# の型に依存しません。

            var length = Request.ContentLength;
            var bytes = new byte[length];
            Request.InputStream.Read(bytes, 0, length);
于 2013-09-25T04:47:01.650 に答える
0

これを試して:

クライアント:

<script src="http://code.jquery.com/jquery-1.10.2.min.js" ></script>
<div class='wrapper' >
    <input type='file' class='target' id='targetinput' />
</div>

Javascript:

var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append("blob.blob", document.getElementById('targetinput').files[0]);
xhr.open("POST", "/Home/SubmitSound", true);
xhr.send(fd);

サーバ:

[HttpPost]
public ActionResult SubmitSound(SoundBlob blob)
{
        var fileName = Server.MapPath(string.Format("/Content/Sound/{0}.wav", Environment.TickCount));
        blob.blob.SaveAs(fileName);
        return new JsonResult { Data = "Saved successfully" };
}

完全に動作します、私はちょうどそれをチェックアウトしました

于 2013-09-23T06:36:57.343 に答える