Skip to content

Commit bc581ef

Browse files
author
Leonid
committed
Add AudioController
1 parent bc62f54 commit bc581ef

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,4 @@ eform-client/src/app/plugins/modules/
372372
eFormAPI/Plugins/
373373
eFormAPI/eFormAPI/Areas/HelpPage/HelpPage.css
374374

375-
eFormAPI/eFormAPI/dataFolder/picture/
375+
eFormAPI/eFormAPI/output/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.IO;
2+
using System.Net;
3+
using System.Net.Http;
4+
using System.Net.Http.Headers;
5+
using System.Web;
6+
using System.Web.Http;
7+
8+
namespace eFormAPI.Web.Controllers
9+
{
10+
[Authorize]
11+
public class AudioController : ApiController
12+
{
13+
[HttpGet]
14+
[Route("api/audio/eform-audio/{fileName}")]
15+
public HttpResponseMessage GetAudio(string fileName)
16+
{
17+
var filePath = HttpContext.Current.Server.MapPath($"~/output/datafolder/picture/{fileName}.wav");
18+
if (!File.Exists(filePath))
19+
{
20+
return new HttpResponseMessage(HttpStatusCode.NotFound);
21+
}
22+
const string mime = "vnd.wave";
23+
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
24+
var result = new HttpResponseMessage(HttpStatusCode.OK)
25+
{
26+
Content = new StreamContent(fileStream)
27+
};
28+
result.Content.Headers.ContentDisposition =
29+
new ContentDispositionHeaderValue("attachment") {FileName = fileName};
30+
result.Content.Headers.ContentType =
31+
new MediaTypeHeaderValue($"audio/{mime}");
32+
return result;
33+
}
34+
}
35+
}

eFormAPI/eFormAPI/Global.asax.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected void Application_Start()
3030
try
3131
{
3232
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
33-
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
33+
var section = (ConnectionStringsSection) configuration.GetSection("connectionStrings");
3434
var connString = section.ConnectionStrings["eFormMainConnection"].ConnectionString;
3535
if (!connString.IsNullOrEmpty())
3636
{
Binary file not shown.

eFormAPI/eFormAPI/eFormAPI.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@
262262
<Compile Include="Controllers\CasesController.cs" />
263263
<Compile Include="Controllers\EntitySelectController.cs" />
264264
<Compile Include="Controllers\EntitySearchController.cs" />
265+
<Compile Include="Controllers\AudioController.cs" />
265266
<Compile Include="Controllers\ImagesController.cs" />
266267
<Compile Include="Controllers\SettingsController.cs" />
267268
<Compile Include="Controllers\TagsController.cs" />

0 commit comments

Comments
 (0)