2016-12-12 12 views
0

次の機能を使用してローカルサーバにイメージをアップロードしています。リクエストのパラメータにリストを追加する

uploadPhoto() { 
    let ft = new Transfer(); 
    let filename = this.imagePath.substr(this.imagePath.lastIndexOf('/') + 1); 
    let options = { 
     fileKey: 'file', 
     fileName: filename, 
     httpMethod: 'POST', 
     mimeType: 'image/jpeg', 
     chunkedMode: false, 
     headers: { 
     'Content-Type': undefined, 
     'Content-Disposition': "attachment; filename=" + filename 
     }, 
     params: { 
     fileName: filename, 
     users: this.user_list, 
     name: this.event_name, 
     event_type: this.event_type, 
     date: this.date, 
     start: this.timeStarts, 
     location: this.location, 
     info: this.description 
     } 
    }; 
    alert(options); 
    ft.upload(this.imagePath, UPLOAD_URL, options, true) 
     .then((result: any) => { 
     this.imageChosen = 0; 
     this.imagePath = ''; 
     alert(JSON.stringify(result)); 
     }).catch((error: any) => { 
     alert(JSON.stringify(error)); 
     }); 
    } 

私がサーバー側をチェックしたとき、要求には「ユーザー」パラメータが含まれていません。しかし、もし私がそれを送ったら、

users: JSON.stringfy(this.user_list) 

私は要望に応じて見ることができますが、文字列ではないリストとして必要です。それで、それをリストとして送る方法はありますか?

+0

どうすればいいですか?正しいjsonに変換する必要があります。 – Sakuto

答えて

0

@Sakutoは、上記の彼のコメントで述べたように、あなたはのparamsをシリアル化する必要があるが、有効なJSONにオブジェクト:サーバー上

let params = { 
    fileName: filename, 
    users: this.user_list, 
    name: this.event_name, 
    event_type: this.event_type, 
    date: this.date, 
    start: this.timeStarts, 
    location: this.location, 
    info: this.description 
} 

... 
params: JSON.stringfy(params) 
... 

、あなたはあなたのための適切なJSONのユーティリティメソッドを使用してのparamsデシリアライズする必要がありますハイテクスタック。例えば。ノードの場合:

params = JSON.parse(params); 
関連する問題