2017-10-16 6 views
0

NativeScript로 만든 모바일 앱에서 C#으로 작성한 webapi에 게시하려고합니다.NativeScript - nativescript-background-http가 작동하지 않습니다.

나는 nativescript-imagepickernativescript-background-http을 모두 사용하고 있습니다. 그러나 error 이벤트는 항상 발생합니다. 이것은 내가 이미지의 URI를 가지고 어떻게

import * as imagepicker from "nativescript-imagepicker"; 
import * as bghttp from "nativescript-background-http"; 

: 내 두 수입 :

는 내가 가지고있는 코드입니다

SelectImage(): void { 
     let context = imagepicker.create({ 
      mode: "single" 
     }); 

     context.authorize() 
       .then(() => { return context.present() }) 
       .then((selection) => { 
        selection.forEach((selected) => { 
         this.signupModel.CIPath = selected.fileUri; 
        }) 
       }).catch((e) => { 
        console.log(e); 
       }); 
    } 

을 내가 노력하고있어 방법이있다 데이터 게시 :

SignUp(): void { 
     let session = bghttp.session("image-upload"); 

     let request = { 
      url: "http://localhost:53286/api/Home/Signup", 
      method: "POST", 
      headers: { 
       "Content-Type": "application/octet-stream", 
       "File-Name": this.signupModel.CIPath 
      }, 
      description: "{ 'uploading': 'Uploading file...' }" 
     }; 

     let task: bghttp.Task; 

     let params = [{ 
      name: "ImageCI", mimeType: "image/jpeg", filename: this.signupModel.CIPath 
     }, { 
      name: "Rut", value: this.signupModel.Rut 
     }, { 
      name: "Name", value: this.signupModel.Name 
     }, { 
      name: "Address", value: this.signupModel.Address 
     }, { 
      name: "Commune", value: this.signupModel.Commune 
     }, { 
      name: "PhoneNumber", value: this.signupModel.PhoneNumber 
     }, { 
      name: "Email", value: this.signupModel.Email 
     }, { 
      name: "Password", value: this.signupModel.Password 
     }]; 

     task = session.multipartUpload(params, request); 

     task.on("error", (response: any) => { 
      console.log(JSON.stringify(response)); 
      alert({title: "Sistema 3 Esferas", message:"Error subiendo imagen...", okButtonText: "Cerrar"}); 
     }); 

     task.on("responded", (response: any) => { 
      console.log(JSON.stringify(response)); 
     }); 
    } 

내가 뭘 잘못하고 있니? 미리 감사드립니다. :)

+1

에뮬레이터에서 테스트 하시겠습니까? 그래서 기본 설정이'localhost'와 함께 작동하지 않는다는 것을 명심하십시오 - 자세한 내용은이 스레드를보세요 https://stackoverflow.com/a/39958955/4936697 –

+0

무엇이 오류 응답입니까? –

답변

0

감사합니다. Nick, 의견을 남겨주세요.

네, 효과가있었습니다.

url: "http://localhost:53286/api/Home/Signup" 

에 : 난 그냥이 라인 변경했다

url: "http://10.0.2.2:53286/api/Home/Signup" 

을 그리고 그 문제를 해결했다. :)

관련 문제