0

如何使用 Java 应用程序使用 Couchdb4J 库将系统文件作为附件添加到 Couchdb 数据库?

我尝试修改下面的示例代码,但有一个未解决的错误。有人知道我的错误在哪里以及如何解决吗?提前致谢。

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import com.fourspaces.couchdb.CouchResponse;
import com.fourspaces.couchdb.Database;
import com.fourspaces.couchdb.Document;
import com.fourspaces.couchdb.Session;

public class FileScanner {

Session priceListDocsSession = new Session("localhost",5984);
  Database db = priceListDocsSession.getDatabase("filesdb");

  public static void main(String[] args) {
  FileScanner fs = new FileScanner();

 fs.processDir(new File("C:\\CouchDB"));
}

void processDir(File f) {
if (f.isFile()) {
  Map<String, Object> doc = new HashMap<String, Object>();
  doc.put("name", f.getName());
  doc.put("path", f.getAbsolutePath());
  doc.put("size", f.length());


  db.saveDocument(doc);
  InputStream is = new FileInputStream(f);
  String att=db.putAttachment(doc.getId(),doc.getRev(),f,is);
   } 
else {
  File[] fileList = f.listFiles();
  if (fileList == null) return;
  for (int i = 0; i < fileList.length; i++) {
    try {
      processDir(fileList[i]);
     } catch (Exception e) {
      System.out.println(e);
        }

      }
    }
  }
}

错误出现在db.saveDocument(doc);

String att=db.putAttachment(doc.getId(),doc.getRev(),f,is);这么说.getId()并且getRev()对于类型 Map 是未定义的

4

1 回答 1

0

我设法通过在类路径上添加一些 jcouchdb 依赖项来解决问题。

于 2013-10-14T11:31:01.833 回答