fix mimetypes

This commit is contained in:
Damien Ostler 2024-03-01 19:35:34 -05:00
parent acd022cf41
commit 2b3f49b5e9
5 changed files with 31 additions and 4 deletions

View File

@ -86,7 +86,8 @@ public class ArtistRequestsController: Controller
if(reference==null)
return NotFound();
var content = await _storageService.DownloadImageAsync(reference.FileReference);
return new FileStreamResult(content, "application/octet-stream");
var mimeType = _storageService.GetMimeType(reference.FileReference);
return new FileStreamResult(content, mimeType);
}
[HttpGet]
@ -142,7 +143,8 @@ public class ArtistRequestsController: Controller
if(reference==null)
return NotFound();
var content = await _storageService.DownloadImageAsync(reference.FileReference);
return new FileStreamResult(content, "application/octet-stream");
var mimeType = _storageService.GetMimeType(reference.FileReference);
return new FileStreamResult(content, mimeType);
}

View File

@ -822,7 +822,8 @@ public class CustomerRequestsController : Controller
if(reference==null)
return NotFound();
var content = await _storageService.DownloadImageAsync(reference.FileReference);
return new FileStreamResult(content, "application/octet-stream");
var mimeType = _storageService.GetMimeType(reference.FileReference);
return new FileStreamResult(content, mimeType);
}
[HttpPost]
@ -911,7 +912,8 @@ public class CustomerRequestsController : Controller
if(reference==null)
return NotFound();
var content = await _storageService.DownloadImageAsync(reference.FileReference);
return new FileStreamResult(content, "application/octet-stream");
var mimeType = _storageService.GetMimeType(reference.FileReference);
return new FileStreamResult(content, mimeType);
}
#endregion

View File

@ -4,4 +4,6 @@ public interface IStorageService
{
public Task<string> UploadImageAsync(Stream fileStream, string fileName);
public Task<Stream> DownloadImageAsync(string fileRefrence);
public string GetMimeType(string fileReference);
}

View File

@ -51,5 +51,10 @@ namespace comissions.app.api.Services.Storage
var stream = await response.Content.ReadAsStreamAsync();
return stream;
}
public string GetMimeType(string fileReference)
{
throw new NotImplementedException();
}
}
}

View File

@ -34,7 +34,23 @@ namespace comissions.app.api.Services.Storage
return fileReference;
}
public string GetMimeType(string fileReference)
{
var extension = Path.GetExtension(fileReference).ToLowerInvariant();
switch (extension)
{
case ".jpg":
case ".jpeg":
return "image/jpeg";
case ".png":
return "image/png";
case ".gif":
return "image/gif";
default:
throw new NotSupportedException($"File extension {extension} is not supported.");
}
}
public async Task<Stream> DownloadImageAsync(string fileReference)
{
// Get the file path based on the provided file reference