2017-09-07 24 views
0

Androidカメラ(cordova-plugin-camera)で撮影した画像をアップロードしようとしています。Phonegap Vue js Androidのカメラ画像をAPIサーバーにアップロード

file:///storage/emulated/0/Android/data/.../1234.jpg 

がどのようにモバイルアプリからサーバに画像をアップロードするためにそれを使用することができます。そのために私のコードは次のように私はパスを持って私のthis.newUnit.addedPic

takePicture() { 
    navigator.camera.getPicture(result => { 
    this.newUnit.addedPic = true 
    this.newUnit.image = result 
    }, error => { 
    alert(error); 
    }, 
    { 
    sourceType : Camera.PictureSourceType.CAMERA, 
    destinationType: Camera.DestinationType.FILE_URI, 
    encodingType: Camera.EncodingType.JPEG, 
    }); 
}, 

のですか? 私のWebパーツでは、FormDataを使って画像をアップロードしています。

私は変数をFileTransferでそれをやろうとしましたが、私は、エラーコード1を取得:

解決しよう
let win = r => {alert(`win`)} 
    let fail = error => { 
     alert("An error has occurred: Code = " + error.code); 
     console.log("upload error source " + error.source); 
     console.log("upload error target " + error.target); 
    } 
    var options = new FileUploadOptions(); 
    options.fileKey = "file"; 
    options.fileName = this.newUnit.image.substr(this.newUnit.image.lastIndexOf('/') + 1); 
    options.mimeType = "image/jpeg"; 

    var params = {}; 
    params.name = "test"; 
    params.creator = 3; 

    options.params = params; 

    var ft = new FileTransfer(); 
    ft.upload(this.newUnit.image, encodeURI("http://myserver/api/v0/units/"), win, fail, options); 

答えて

0

を。問題は空のヘッダーとhttpメソッドのためでした。

var headers = { 'Authorization':`Token ${token}` }; 
    options.headers = headers; 

    options.httpMethod= "POST"; 
    options.chunkedMode = true;` 
関連する問題