public async Task <ActionResult> Post([FromBody] Other other, IFormFile stream) { try { VerifyUser(); _validateService.Validate(other); //upload file if (CloudStorageAccount.TryParse(config.Value.StorageConnection, out CloudStorageAccount storageAccount)) { CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(config.Value.Container); var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var stringChars = new char[8]; var random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } var finalString = new String(stringChars); CloudBlockBlob blockBlob = container.GetBlockBlobReference(finalString + stream.FileName); string fileUrl = blockBlob?.Uri.ToString(); other.FileUrl = fileUrl.ToString(); await blockBlob.UploadFromStreamAsync(stream.OpenReadStream()); } else { return(null); } await _otherService.Create(other); return(CreatedAtRoute("Get", new { Id = other.Id }, other)); } catch (ServiceValidationExeption e) { var result = new ResultFormatter(API_VERSION, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(result)); } catch (Exception e) { var result = new ResultFormatter(API_VERSION, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }