2017-05-17 11 views
0

현재 대화 흐름 중에 사용자가 파일을 봇에 업로드 할 수있게하려고합니다. 거기에서 봇이 파일을 가져 와서 blob 저장소에 업로드합니다. 파일이 들어 오면 content 속성은 null이지만 콘텐츠 url, name 및 type은 모두 올바른 값을 갖습니다.봇 프레임 워크로 사용자로부터 업로드 된 파일 저장하기 #

public virtual async Task StackTraceGathered(IDialogContext context, IAwaitable<IMessageActivity> argument) 
    { 
     var message = await argument; 
     FileName = message.Attachments[0].Name; 
     HttpPostedFileBase file = (HttpPostedFileBase)message.Attachments[0].Content; 

     string filePath = HttpContext.Current.Server.MapPath("~/Files/" + file.FileName); 
     file.SaveAs(filePath); 

     if (message.Attachments != null && message.Attachments.Any()) 
     { 
      var attachment = message.Attachments.First(); 
      using (HttpClient httpClient = new HttpClient()) 
      { 
       // Skype & MS Teams attachment URLs are secured by a JwtToken, so we need to pass the token from our bot. 
       if ((message.ChannelId.Equals("skype", StringComparison.InvariantCultureIgnoreCase) || message.ChannelId.Equals("msteams", StringComparison.InvariantCultureIgnoreCase)) 
        && new Uri(attachment.ContentUrl).Host.EndsWith("skype.com")) 
       { 
        var token = await new MicrosoftAppCredentials().GetTokenAsync(); 
        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); 
       } 

       var responseMessage = await httpClient.GetAsync(attachment.ContentUrl); 

       var contentLenghtBytes = responseMessage.Content.Headers.ContentLength; 

       await context.PostAsync($"Attachment of {attachment.ContentType} type and size of {contentLenghtBytes} bytes received."); 
      } 
     } 
     else 
     { 
      await context.PostAsync("Hi there! I'm a bot created to show you how I can receive message attachments, but no attachment was sent to me. Please, try again sending a new message including an attachment."); 
     } 
     PromptDialog.Text(context, ProblemStartDuration, "How long has this been an issue? (Provide answer in days, if issue has been occurring for less than one day put 1)."); 

     context.Wait(this.StackTraceGathered); 
    } 

답변

1

나는이 문제가 보이지 않지만 콘텐츠 속성이 있어야한다고 생각합니다. 그것은 당신이 단지 URL을 필요로하지 않을 것입니다. 두 대안 :

  • 가 (당신이 질문을 사용하는 코드 등) 로봇의 첨부 파일을 다운로드 StartCopyFromBlob 같은 것을 사용하여 URL에서 직접 첨부 파일을 업로드 할 수
  • 시도 BLOB 저장소에 업로드 (this을 확인)
+0

다른 스택 오버플로의 지시를 따르는 동안 첨부 파일을 직접 업로드하려고했습니다. 원격 서버가 404 찾을 수 없음 오류를 반환했습니다. – race155

+0

브라우저에서 URL로 이동하면 어떻게됩니까? –

+0

콘텐츠 URL은 파일을 다운로드하도록 허용하거나 이미지 인 경우 이미지를 표시합니다. – race155

관련 문제