attachments not working?
Created by: squirrelpiles
the following code is a stripped down version of your example. The file api.png
is in the same directory as the code.
when I run, db
is created, document
is created. File does not get uploaded/attached. If I look at _attachments
in the created document, there is an single value api.png
that says "8 bytes, image/png" under it.
What am I doing wrong? I expected the file to be uploaded as the attachment.
code:
local base = '/home/dave/creeksidedepot/ferret/src/lua/'
local couchdb = require 'Spore'.new_from_spec(
base .. 'server.json',
base .. 'database.json',
base .. 'document.json',
base .. 'design.json',
{ base_url = 'http://127.0.0.1:5984/' })
couchdb:enable_if(function (req) return req.env.spore.caller ~= 'get_attachment' end, 'Format.JSON')
local r = couchdb:create_db{ db = 'albums' }
assert(r.body.ok)
local r = couchdb:add_document{
db = 'albums',
id = '1234567',
payload = {
title = "There is Nothing Left to Lose",
artist = "Foo Fighters",
},
}
local rev2 = r.body.rev
local r = couchdb:add_attachment{
db = 'albums',
id = '1234567',
rev = rev2,
file = 'api.png',
content_type = 'image/png',
payload = '@api.png',
}
assert(r.body.ok)
print("id", r.body.id)
print("rev", r.body.rev)