2016-11-08 8 views
0

私はedgee:slingshotをMeteor + Reactプロジェクトに追加しようとしていましたが、何らかの理由で同じエラーが発生し続けます。 "ディレクティブmyFileUploadsが存在しないようです[無効な指令] "edgee:slingshot error [無効なディレクティブ]

私はすべての情報を実装するためにチュートリアルに従ってきましたが、私のコードに何が間違っているのか分からないようです。

ご協力いただきまして誠にありがとうございます。

私のアップロード・ルール・ファイル:

Slingshot.fileRestrictions("myFileUploads", { 
 
    allowedFileTypes: ["image/png", "image/jpeg", "image/gif"], 
 
    maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited) 
 
}); 
 

 
Slingshot.createDirective("myFileUploads", Slingshot.S3Storage, { 
 
    bucket:    "ec2016", 
 
    region:     "eu-central-1", 
 
    acl:     "public-read", 
 

 
    authorize: function() { 
 
    //Deny uploads if user is not logged in. 
 
    if (!this.userId) { 
 
     var message = "Please login before posting files"; 
 
     throw new Meteor.Error("Login Required", message); 
 
    } 
 

 
    return true; 
 
    }, 
 

 
    key: function (file) { 
 
    //Store file into a directory by the user's username. 
 
    var user = Meteor.users.findOne(this.userId); 
 
    return user.username + "/" + file.name; 
 
    } 
 
});

マイ形式:その横に

export default class AddSpark extends Component { 
 
    constructor(props) { 
 
    super(props); 
 

 
    this.upload = this.upload.bind(this) 
 
    } 
 

 
    createSpark(event){ 
 
    event.preventDefault(); 
 
    const spark = { 
 
     city: this.city.value, 
 
     person: this.person.value, 
 
     location: this.location.value, 
 
     title: this.title.value, 
 
     content: this.content.value, 
 
     url: this.url.value, 
 
    } 
 
    console.log(spark); 
 
    } 
 

 
    componentWillMount(){ 
 
    // we create this rule both on client and server 
 
    Slingshot.fileRestrictions("myFileUploads", { 
 
     allowedFileTypes: ["image/png", "image/jpeg", "image/gif"], 
 
     maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited) 
 
    }); 
 
    } 
 

 

 
    upload(){ 
 
    var uploader = new Slingshot.Upload("myFileUploads"); 
 

 
    uploader.send(document.getElementById('input').files[0], function (error, downloadUrl) { 
 
     if (error) { 
 
     // Log service detailed response 
 
     alert (error); 
 
     } 
 
     else { 
 
     Meteor.users.update(Meteor.userId(), {$push: {"profile.files": downloadUrl}}); 
 
     } 
 
    }); 
 
    } 
 

 
    render() { 
 
    return (
 
     <div> 
 
     <form ref={(input) => this.sparkForm = input} onSubmit={(e) => this.createSpark(e)}> 
 

 
      <ControlLabel>Select your city</ControlLabel> 
 
      <select id="formControlsCity" placeholder="Choose your city" className="form-control" onClick={ moreOptions } ref={(input) => this.city = input}> 
 
       <option value="select">Choose your city</option> 
 
       <option value="Beijing">Beijing</option> 
 
       <option value="Shanghai">Shanghai</option> 
 
       <option value="Chengdu & Chongqing">Chengdu & Chongqing</option> 
 
      </select> 
 
     
 
      <ControlLabel>Select your person</ControlLabel> 
 
      <select id="formControlsPerson" placeholder="Choose your person" className="form-control" ref={(input) => this.person = input}> 
 
       <option value="select">First select your city</option> 
 
      </select> 
 
    
 

 
      <ControlLabel>Select your location</ControlLabel> 
 
      <select id="formControlsLocation" placeholder="Choose your location" className="form-control" ref={(input) => this.location = input}> 
 
       <option value="select">First select your city</option> 
 
      </select> 
 

 
      <ControlLabel>Title</ControlLabel> 
 
      <input type="text" label="Title" placeholder="Enter your title" className="form-control" ref={(input) => this.title = input}/> 
 
      
 

 
      <ControlLabel>Content</ControlLabel> 
 
      <textarea placeholder="Enter your comment here" className="form-control" ref={(input) => this.content = input}/> 
 

 
      <div className="upload-area"> 
 
       <p className="alert alert-success text-center"> 
 
       <span>Click or Drag an Image Here to Upload</span> 
 
       <input type="file" id="input" ref={(input) => this.url = input} onChange={this.upload} /> 
 
       </p> 
 
      </div> 
 

 
      <Button type="submit">Submit</Button> 
 
     </form> 
 
     </div> 
 
)} 
 
}

私はofcourseのも、私が保存setting.jsonファイルを持っています私のS3キー。

素晴らしい一日を過ごし、笑顔を忘れないでください。

答えて

0

私はすでにこれを修正することができました。私のupload-rules.jsがサーバフォルダ内にあると思っていました。それは正しいものではないことが判明しました。それを右のフォルダに移動した後は、すべて動作します。

同じ問題が発生した場合は、ファイルが適切な場所にあるかどうかを再度確認してください。

関連する問題