【问题标题】:Grunt task for uploading a file to CouchDB using request使用请求将文件上传到 CouchDB 的 Grunt 任务
【发布时间】:2014-07-30 02:55:44
【问题描述】:

在我的Gruntfile.coffee,我设置了一个任务:

grunt.registerTask 'couch_upload', 'CouchDB upload', ->
  done = @async()

  assets = ['combined.min.js', 'screen.min.css']
  ddoc = 'http://localhost:5984/mydb/_design/app'
  request = require 'request'
  fs = require 'fs'
  grunt.log.writeln 'Uploading assets...'

  upload = (asset) ->
    # get the revision of the design document
    request.get {json: yes, url: ddoc}, (err, resp, body) ->
      rev = body._rev
      # stream the file and pipe it, so it has the correct Content-Type
      fs.createReadStream('build/' + asset).pipe request.put
        auth: user: 'myusername', password: 'mypass'
        headers: 'If-Match': rev
        url: [ddoc, asset].join '/'
      , -> grunt.log.write ' ' + asset

  upload asset for asset in assets

  done()

但是我在 Grunt 的日志和 Couch 的日志上都看不到任何上传的内容。

你能告诉我我做错了什么吗?

【问题讨论】:

    标签: coffeescript gruntjs couchdb


    【解决方案1】:

    听起来您需要向 CouchDB-Lucene 提出功能请求:https://github.com/rnewson/couchdb-lucene/issues — 如果可能的话,它看起来还没有启用该功能。

    【讨论】:

    • 感谢您为回答所做的努力,但 Lucene 与此无关。 CouchDB 支持附件上传就好了。这是某种异步问题;部分/全部发生:1)第二个文件报告 409(文档冲突),2)fs 管道覆盖所有其他标头(如 auth 和 If-Match)3)JSON.strigify 将顺序与 multipart/related 混淆。我可以让它只使用一个文件,但不能使用多个。即使在不同的任务中。
    • 我的意思是在另一个问题上发布这个,忽略我。对不起! :D
    猜你喜欢
    • 2017-09-02
    • 1970-01-01
    • 2019-03-04
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多