2017-12-31 54 views
0

@Simon_Grimm 블로그의 튜토리얼을 따라 갔다. 그것은 Node.js에 간단한 이온 이미지 업로드입니다. 업로드를 제외한 모든 것이 완벽하게 작동합니다. 서버에서 내 이오닉 클라이언트로 이미지를 표시 할 수 있으며 삭제할 수 있습니다. 삭제 및 이미지 가져 오기에 대한 내 HTTP 요청이 완벽하게 작동합니다. 업로드 버튼을 클릭 할 때마다 내 백엔드와 통신 할 수 없습니다. http_status = null, body = null 등의 오류가 발생했습니다. 왜 작동하지 않는지 이해할 수 없습니까? 원시 파일 전송으로 파일을 업로드하는 경우. 내가 아는 한 내 문제는 내 업로드 메소드가 HTTP 요청을 트리거 할 수 없다는 것입니다. 누군가 나를 안내 할 수 있으면 기뻐할 것입니다.Ionic-3 이미지 FileTransfer Native에서 NodeJs 서버로

내 이미지 업로드 serveice 제공 업체는 여기에,

이미지 업로드 - setting.ts 내 uploadMethod이다. 내 오류가이 return filetransfer callback (err)=>

import { Injectable } from '@angular/core'; 
import 'rxjs/Rx'; 
import {Http, Response} from "@angular/http"; 
import { Observable } from 'rxjs/Rx'; 
import { Headers } from '@angular/http'; 
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer'; 
import { File } from '@ionic-native/file'; 


@Injectable() 
export class ImageUploadSettingsProvider { 

    constructor(private http: Http, private transfer: FileTransfer, private file: File) { 
    console.log('Hello ImageUploadSettingsProvider Provider'); 


    } 



    imageUpload(imageData, desc){ 
    let requestUrl = 'http://localhost:5000/images/'+ 'upload'; 
    var destination = imageData; 

    var options: FileUploadOptions = { 
      fileKey: 'file', 
      chunkedMode: true, 
      mimeType: 'multipart/form-data', 
      params: { 'desc': desc } 
    }; 
    const fileTransfer: FileTransferObject = this.transfer.create(); 
    return fileTransfer.upload(destination,requestUrl,options).then(
     (data)=>{ 
      console.log('ImageProvider Upload Data-',data); 
     }, 
     (err)=>{ 
      console.log(err); 
     } 
    ) 

    }; 



} 

그것에서 트리거 된 내 uploadMethod successfull .then((data)=>{})이 작동하지 않는 것을 의미한다.

내 html.ts 내가 64 기수로 편대를 변경하려고

onSubmit(form: NgForm){ 
    this.imageProvider.imageUpload(this.imageUrl, form.value.desc).then(
    (res)=>{ 
     form.reset(); 
    }, 
    (err)=>{ 
     console.log(err); 
    } 
); 
}; 


onTakePhoto(){ 

     const options: CameraOptions = { 
       quality: 100, 
       encodingType: this.camera.EncodingType.JPEG, 
       correctOrientation: true, 
       allowEdit: true, 
       destinationType: this.camera.DestinationType.FILE_URI, 
       mediaType: this.camera.MediaType.PICTURE, 
       sourceType: this.camera.PictureSourceType.CAMERA, 
      } 

     this.camera.getPicture(options).then((imageData)=>{ 


/* 
      let base64Image = 'data:image/jpeg;base64,' + imageData; 
      this.imageUrl = base64Image */ 


     this.imageUrl = imageData; 


    }, (err) => { 
      const toast = this.toastCtr.create({ 
       message:'Could Not save the image. Please try again', 
       duration:2500 
      }); 
      toast.present(); 
      this.camera.cleanup(); 
     }); 

} 

입니다. 불행히도 그것은뿐만 아니라 작동하지 않습니다. 그런 다음 주석을 제거합니다. 이제는 1 주일이 지난 지금부터 머리카락을 잡아 당깁니다. ImageUploadSettingsProvider에서 당신의 노력

답변

0

에 대한

덕분에, 응답이이

mimeType: "image/jpg", 
+0

안녕 @Sherif_Abdulmawala에

mimeType: 'multipart/form-data', 

, 감사를 변경해보십시오. 하지만 파일을 양식 데이터로 보내고 있습니다. 이미지 만 보내면 base64 Image Formate와 같은 형식을 처리해야합니다. 이 해결책은 도움이되지 못했습니다. 나는 이미 바뀌었다. 내 http 요청을 실행하지 않습니다. – Garten786

관련 문제