Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 如何将Meteor中的照片上载到S3并使其与数据库项同步?_Mongodb_File Upload_Meteor_Amazon S3 - Fatal编程技术网

Mongodb 如何将Meteor中的照片上载到S3并使其与数据库项同步?

Mongodb 如何将Meteor中的照片上载到S3并使其与数据库项同步?,mongodb,file-upload,meteor,amazon-s3,Mongodb,File Upload,Meteor,Amazon S3,我正在创建一个cookbook web应用程序,希望每个新食谱都能上传一张图片 我正在使用这个包:Amazon S3文件上传器() 单击“提交”以获取新开胃菜时,我可以成功完成两件事: 向数据库中添加新的开胃菜名称和说明 将上传的照片添加到s3数据库 我是MongoDB/Meteor的新手,我不确定如何将这两者联系起来,以便在提交表单时将图像链接到配方名称和说明 我是否需要在开胃菜集合中创建一个文档,说明s3图像应该放置的字段?如果这是正确的方向,我该怎么做 到目前为止,已部署的版本可以在:re

我正在创建一个cookbook web应用程序,希望每个新食谱都能上传一张图片

我正在使用这个包:Amazon S3文件上传器()

单击“提交”以获取新开胃菜时,我可以成功完成两件事:

  • 向数据库中添加新的开胃菜名称和说明
  • 将上传的照片添加到s3数据库
  • 我是MongoDB/Meteor的新手,我不确定如何将这两者联系起来,以便在提交表单时将图像链接到配方名称和说明

    我是否需要在开胃菜集合中创建一个文档,说明s3图像应该放置的字段?如果这是正确的方向,我该怎么做

    到目前为止,已部署的版本可以在:reed-cookbook.meteor.com上看到

    我的表格html:

    <template name="appetizerForm">
        <!-- This is the appetizer modal -->
        <div class="modal fade" id="myAppModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Add An Appetizer</h4>
              </div>
              <div class="modal-body">
                  <!-- This is the appetizer form -->
                  <form>
                      <div class="form-group">
                          <label for="inputNewLabel">Name</label>
                          <input type="text" class="form-control" id="addNewAppetizer" name="appName" placeholder="What is the name of this appetizer?">
                      </div>
                      <div class="form-group">
                          <label for="inputNewLabel">Description</label>
                          <input type="text" class="form-control" id="addNewAppDesc" name="appDesc" placeholder="Share details about your appetizer.">
                      </div>
                      <div class="form-group">
                          <label for="inputNewLabel">Add Photo</label>
                          {{>s3}}
                          <p class="help-block">Upload a photo of your appetizer.</p>
                      </div>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary" value="submitApp">Submit Appetizer</button>
                </form>
            </div>
            </div>
          </div>
        </div>
    </template>
    

    您肯定需要将S3URL添加到集合架构中,这可以在使用
    Mongo.collection.update
    在文件上载回调中接收url时完成

    [...]
    var appetizerId = Appetizers.insert({
      name: addNewAppetizerVar,
      description: addNewAppDescVar
    });
    var files = $("input.file_bag")[0].files;
    S3.upload({
      files: files,
      path: "subfolder"
    }, function(error, s3Url){
      Appetizers.update(appetizerId, {
        $set: {
          imageUrl: s3Url
        }
      });
    });
    [...]
    
    然后,您将能够使用
    
    
    [...]
    var appetizerId = Appetizers.insert({
      name: addNewAppetizerVar,
      description: addNewAppDescVar
    });
    var files = $("input.file_bag")[0].files;
    S3.upload({
      files: files,
      path: "subfolder"
    }, function(error, s3Url){
      Appetizers.update(appetizerId, {
        $set: {
          imageUrl: s3Url
        }
      });
    });
    [...]
    
    <template name="appetizer">
      <h3>{{name}}</h3>
      <p>{{description}}</p>
      <img src="{{imageUrl}}" alt="{{name}}">
    </template>