/// <inheritdoc /> public async Task <ServiceResponse <int> > UploadModel(AddGuideModelDto model) { var guideId = (int)model.GuideId !; var(isEditable, accessResponse, guide) = await GuideIsEditable <int>(guideId); if (!isEditable) { return(accessResponse); } using var formData = new MultipartFormDataContent(); // 'File' field var bodyFile = new StreamContent(model.File.OpenReadStream()); bodyFile.Headers.Add("Content-Type", "application/octet-stream"); bodyFile.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"model.stp\""); formData.Add(bodyFile, "file"); // 'From' field var extFrom = new StringContent("stp"); extFrom.Headers.Add("Content-Disposition", "form-data; name=\"from\""); formData.Add(extFrom, "from"); // 'To' field var extTo = new StringContent("glb"); extTo.Headers.Add("Content-Disposition", "form-data; name=\"to\""); formData.Add(extTo, "to"); var serviceResponse = new ServiceResponse <int>(); try { // MPU Cloud Exchanger using var client = _clientFactory.CreateClient("converter"); var response = await client.PostAsync("/model", formData); response.EnsureSuccessStatusCode(); var data = JObject.Parse(await response.Content.ReadAsStringAsync()); var glbModel = Convert.FromBase64String(data["output"].ToString()); await _fileManager.SaveFile(guideId, "model.glb", glbModel); serviceResponse.StatusCode = 201; serviceResponse.Data = guideId; serviceResponse.Message = "Model was converted to and saved as glb successfully."; serviceResponse.MessageRu = "Модель была успешно конвертирована в glb и сохранена."; return(serviceResponse); } catch { serviceResponse.StatusCode = 500; serviceResponse.Message = "Unable to convert the model."; serviceResponse.MessageRu = "Не удалось конвертировать модель."; return(serviceResponse); } }
public async Task <IActionResult> UploadModel([FromForm] AddGuideModelDto model) { var serviceResponse = await _guidesService.UploadModel(model); return(StatusCode(serviceResponse.StatusCode, serviceResponse.ToControllerResponse())); }