public async Task UpdateModelAsync(string modelId, UpdateModelRequest request, string sketchFabToken, TokenType tokenType) { try { _logger.LogInformation($"Updating model [{modelId}]."); if (string.IsNullOrWhiteSpace(modelId)) { throw new ArgumentNullException(nameof(modelId)); } HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Patch, $"{SketchfabApiUrl}/models/{modelId}"); httpRequestMessage.AddAuthorizationHeader(sketchFabToken, tokenType); using var form = new MultipartFormDataContent(); form.Headers.ContentType.MediaType = "multipart/form-data"; AddCommonModelFields(form, request); httpRequestMessage.Content = form; var httpClient = _httpClientFactory.CreateClient(); var response = await httpClient.SendAsync(httpRequestMessage); _logger.LogInformation($"{nameof(UpdateModelAsync)} responded {response.StatusCode}"); response.EnsureSuccessStatusCode(); } catch (Exception ex) { _logger.LogError($"Sketchfab update error: {ex.Message}"); throw; } }
private void AddCommonModelFields(MultipartFormDataContent form, UpdateModelRequest request) { form.AddRange(request.Tags, "tags"); form.AddRange(request.Categories, "categories"); }