Skip to content

Commit 250f06f

Browse files
committed
set content-type for uploaded JSON files
1 parent 3d564ae commit 250f06f

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/SMAPI.Web/Controllers/JsonValidatorController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public async Task<ActionResult> PostAsync(JsonValidatorRequestModel? request)
170170

171171
// upload file
172172
string id = Guid.NewGuid().ToString("N");
173-
UploadResult result = await this.Storage.SaveAsync(id, input);
173+
UploadResult result = await this.Storage.SaveAsync(id, input, "application/json");
174174
if (!result.Succeeded)
175175
return this.View("Index", this.GetModel(id, schemaName, isEditView: true).SetContent(input, null, null).SetUploadError(result.UploadError));
176176

src/SMAPI.Web/Controllers/LogParserController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public async Task<ActionResult> PostAsync()
135135

136136
// upload log
137137
string id = Guid.NewGuid().ToString("N");
138-
UploadResult uploadResult = await this.Storage.SaveAsync($"parsed-{id}", JsonConvert.SerializeObject(log));
138+
UploadResult uploadResult = await this.Storage.SaveAsync($"parsed-{id}", JsonConvert.SerializeObject(log), "application/json");
139139
if (!uploadResult.Succeeded)
140140
return this.View("Index", this.GetModel(null, uploadError: uploadResult.UploadError));
141141

src/SMAPI.Web/Framework/Storage/IStorageProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ internal interface IStorageProvider
88
/// <summary>Save a text file to storage.</summary>
99
/// <param name="id">The ID with which to save the result.</param>
1010
/// <param name="content">The content to upload.</param>
11+
/// <param name="contentType">The MIME content type being uploaded.</param>
1112
/// <param name="compress">Whether to gzip the text.</param>
1213
/// <returns>Returns metadata about the save attempt.</returns>
13-
Task<UploadResult> SaveAsync(string id, string content, bool compress = true);
14+
Task<UploadResult> SaveAsync(string id, string content, string contentType, bool compress = true);
1415

1516
/// <summary>Fetch raw text from storage.</summary>
1617
/// <param name="id">The storage ID used to upload the file.</param>

src/SMAPI.Web/Framework/Storage/StorageProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public StorageProvider(IOptions<ApiClientsConfig> clientsConfig, IPastebinClient
5454
}
5555

5656
/// <inheritdoc />
57-
public async Task<UploadResult> SaveAsync(string id, string content, bool compress = true)
57+
public async Task<UploadResult> SaveAsync(string id, string content, string contentType, bool compress = true)
5858
{
5959
// save to Azure
6060
if (this.HasAzure)
@@ -63,7 +63,7 @@ public async Task<UploadResult> SaveAsync(string id, string content, bool compre
6363
{
6464
await using Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
6565
BlobClient blob = this.GetAzureBlobClient(id);
66-
await blob.UploadAsync(stream);
66+
await blob.UploadAsync(stream, new BlobHttpHeaders { ContentType = contentType });
6767

6868
return new UploadResult(id, null);
6969
}

0 commit comments

Comments
 (0)