62,244
社区成员




<form method="post" enctype="multipart/form-data" class="box box-default">
<div class="box-header with-border">
<i class="fa fa-text-width"></i>
<h3 class="box-title">上传需要识别的录音</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="form-group">
<label>上传录音文件:</label>
<input id="input-file" type="file" asp-for="UploadFile" />
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary pull-right"><i class="fa fa-link"></i> 识别</button>
</div>
<!-- /.box-footer -->
</form>
public class TestModel : PageModel
{
public string Error { get; set; }
[BindProperty]
public IFormFile UploadFile { get; set; }
public void OnGet()
{
}
public IActionResult OnPost()
{
string path = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "upload-test.mp3");
if (UploadFile == null)
{
Error = "请选择所要上传的音频文件";
}
else
{
List<string> allowTypes = new List<string> { "audio/wav", "audio/mp3" };
if (!allowTypes.Contains(UploadFile.ContentType))
{
Error = string.Format("演示程序只能上传wav和mp3文件"
, string.Join("、", allowTypes.ConvertAll(x => x.Replace("audio/", ""))));
}
else
{
System.IO.Stream stream = UploadFile.OpenReadStream();
byte[] t = new byte[UploadFile.Length];
stream.Read(t, 0, (int)UploadFile.Length);
System.IO.File.WriteAllBytes(path, t);
UploadFile = null;
Error = null;
}
}
return Page();
}
}
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
EXPOSE 5000 5001
COPY ./publish .
ENTRYPOINT ["dotnet", "test.dll"]
docker build -t test/test .