2016-11-10 12 views
1

私は現在のMeteor ReactプロジェクトでSimple Schemaを使用しようとしていますが、何らかの理由でそれを動作させることができません。fileLinkはスキーマによって許可されていません

これは私のスキーマです:

Comments.schema = new SimpleSchema({ 
 
    city: { 
 
    type: String, 
 
    label: 'The name of the city.' 
 
    }, 
 

 
    person: { 
 
    type: String, 
 
    label: 'The name of the person.' 
 
    }, 
 
    location: { 
 
    type: String, 
 
    label: 'The name of the location.' 
 
    }, 
 
    title: { 
 
    type: String, 
 
    label: 'The title of the comment.' 
 
    }, 
 

 
    content: { 
 
    type: String, 
 
    label: 'The content of the comment.' 
 
    }, 
 

 
    fileLink: { 
 
    type: String, 
 
    regEx: SimpleSchema.RegEx.Url, 
 
    label: 'The url of the file.' 
 
    }, 
 

 
    createdBy: { 
 
    type: String, 
 
    autoValue: function(){ return this.userId }, 
 
    label: 'The id of the user.' 
 
    } 
 
});

そして、これが私のインサートである:

createSpark(event){ 
 
    event.preventDefault(); 
 

 
    const city = this.city.value; 
 
    const person = this.person.value; 
 
    const location = this.location.value; 
 
    const title = this.title.value; 
 
    const content = this.content.value; 
 
    const fileLink = s3Url; 
 

 
    insertComment.call({ 
 
     city, person, location, title, content, fileLink 
 
     }, (error) => { 
 
     if (error) { 
 
       Bert.alert(error.reason, 'danger'); 
 
      } else { 
 
       target.value = ''; 
 
       Bert.alert('Comment added!', 'success'); 
 
      } 
 
     }); 
 
    }

私は戻って取得値を保存していますからamazonをs3Urlというグローバル変数に置き換えます。私は問題なくこの変数をconsole.logにすることができますが、データベースに書きたいときに "fileLinkがスキーマで許可されていません"というエラーが表示されます。

誰かが間違っているのを見てください。ビットメートルを作業中

import { Comments } from './comments'; 
 
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; 
 
import { ValidatedMethod } from 'meteor/mdg:validated-method'; 
 
import { rateLimit } from '../../modules/rate-limit.js'; 
 

 
export const insertComment = new ValidatedMethod({ 
 
    name: 'comments.insert', 
 
    validate: new SimpleSchema({ 
 
    city: { type: String }, 
 
    person: { type: String, optional: true }, 
 
    location: { type: String, optional: true}, 
 
    title: { type: String }, 
 
    content: { type: String }, 
 
    fileLink: { type: String, regEx: SimpleSchema.RegEx.Url }, 
 
    createdBy: { type: String, optional: true } 
 
    }).validator(), 
 
    run(comment) { 
 
    Comments.insert(comment); 
 
    }, 
 
}); 
 

 
rateLimit({ 
 
    methods: [ 
 
    insertComment, 
 

 
    ], 
 
    limit: 5, 
 
    timeRange: 1000, 
 
});

そして、私のmethods.jsファイル:ここで

は私comments.jsファイルですそれに私が間違っているいくつかの事に気づいた。 1.シンプルなスキーマの設定に適切な値がありませんでした。 2.いくつかの問題は、URLに空白が含まれているという事実と関係しています。これを修正するにはどうすればよいですか? 3.私が得ている現在のエラーは次のとおりです: "comments.insert 'を呼び出す結果を配信する際の例外:ReferenceError:target is not defined。"

+0

s3Urlは完全なURLか相対パスですか?あなたはあなたのconsole.log()の出力を表示できますか? 'insertComment.call()'にコードを表示することもできますか? –

+0

@MichelFloydご返信ありがとうございます。私はこれに取り組み続け、この記事を更新しました。 まだ100%で動作していませんが、少なくとも今は別のエラーが発生しています。 私はいくつかの問題は、URLに空白が含まれているという事実と関係していると思います。これを修正する方法はありますか? – Deelux

+0

これは私がs3Urlに保存したURLです: "https://ec2016.s3-eu-central-1.amazonaws.com/undefined/test.png" しかし、ファイル名にスペースが含まれていても動作しません。 – Deelux

答えて

1

私は間違っていることに気づいた。 1.単純なスキーマの設定に適切な価値がありませんでした。 2.いくつかの問題は、URLに空白があるという事実と関係しています。これを修正するにはどうすればよいですか? 3.私が得ている現在のエラーは次のとおりです: "comments.insert 'を呼び出す結果を配信する際の例外:ReferenceError:target is not defined。"

ありがとう@Khang

関連する問題