set content-type for uploaded JSON files

This commit is contained in:
Jesse Plamondon-Willard
2025-04-09 21:26:29 -04:00
parent 3d564ae42c
commit 250f06f200
4 changed files with 6 additions and 5 deletions
@@ -170,7 +170,7 @@ internal class JsonValidatorController : Controller
// upload file
string id = Guid.NewGuid().ToString("N");
UploadResult result = await this.Storage.SaveAsync(id, input);
UploadResult result = await this.Storage.SaveAsync(id, input, "application/json");
if (!result.Succeeded)
return this.View("Index", this.GetModel(id, schemaName, isEditView: true).SetContent(input, null, null).SetUploadError(result.UploadError));
@@ -135,7 +135,7 @@ internal class LogParserController : Controller
// upload log
string id = Guid.NewGuid().ToString("N");
UploadResult uploadResult = await this.Storage.SaveAsync($"parsed-{id}", JsonConvert.SerializeObject(log));
UploadResult uploadResult = await this.Storage.SaveAsync($"parsed-{id}", JsonConvert.SerializeObject(log), "application/json");
if (!uploadResult.Succeeded)
return this.View("Index", this.GetModel(null, uploadError: uploadResult.UploadError));
@@ -8,9 +8,10 @@ internal interface IStorageProvider
/// <summary>Save a text file to storage.</summary>
/// <param name="id">The ID with which to save the result.</param>
/// <param name="content">The content to upload.</param>
/// <param name="contentType">The MIME content type being uploaded.</param>
/// <param name="compress">Whether to gzip the text.</param>
/// <returns>Returns metadata about the save attempt.</returns>
Task<UploadResult> SaveAsync(string id, string content, bool compress = true);
Task<UploadResult> SaveAsync(string id, string content, string contentType, bool compress = true);
/// <summary>Fetch raw text from storage.</summary>
/// <param name="id">The storage ID used to upload the file.</param>
@@ -54,7 +54,7 @@ internal class StorageProvider : IStorageProvider
}
/// <inheritdoc />
public async Task<UploadResult> SaveAsync(string id, string content, bool compress = true)
public async Task<UploadResult> SaveAsync(string id, string content, string contentType, bool compress = true)
{
// save to Azure
if (this.HasAzure)
@@ -63,7 +63,7 @@ internal class StorageProvider : IStorageProvider
{
await using Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
BlobClient blob = this.GetAzureBlobClient(id);
await blob.UploadAsync(stream);
await blob.UploadAsync(stream, new BlobHttpHeaders { ContentType = contentType });
return new UploadResult(id, null);
}