229.6. GridFS 작업 - 생산자 엔드 포인트
229.6.1. count 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
컬렉션의 총 파일 수를 반환하고 OUT 메시지 본문으로 Integer를 반환합니다.
// from("direct:count").to("mongodb-gridfs?database=tickets&operation=count");
Integer result = template.requestBodyAndHeader("direct:count", "irrelevantBody");
assertTrue("Result is not of type Long", result instanceof Integer);
파일 이름 헤더를 제공하여 해당 파일 이름과 일치하는 파일 수를 제공할 수 있습니다.
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
Integer count = template.requestBodyAndHeaders("direct:count", query, headers);
229.6.2. listAll 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
탭 분리 스트림에서 모든 파일 이름 및 해당 ID를 나열하는 리더를 반환합니다.
// from("direct:listAll").to("mongodb-gridfs?database=tickets&operation=listAll");
Reader result = template.requestBodyAndHeader("direct:listAll", "irrelevantBody");
filename1.txt 1252314321
filename2.txt 2897651254
229.6.3. findOne 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
GridFS 시스템에서 파일을 찾아 본문을 콘텐츠의 InputStream으로 설정합니다. 메타데이터에는 헤더도 포함되어 있습니다. 들어오는 헤더에서 Exchange.FILE_NAME을 사용하여 찾을 파일을 결정합니다.
// from("direct:findOne").to("mongodb-gridfs?database=tickets&operation=findOne");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
InputStream result = template.requestBodyAndHeaders("direct:findOne", "irrelevantBody", headers);
229.6.4. create 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
GridFs 데이터베이스에 새 파일을 만듭니다. 이름 및 본문 콘텐츠(입력스트림)에 대한 들어오는 헤더의 Exchange.FILE_NAME을 콘텐츠로 사용합니다.
// from("direct:create").to("mongodb-gridfs?database=tickets&operation=create");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
InputStream stream = ... the data for the file ...
template.requestBodyAndHeaders("direct:create", stream, headers);
229.6.5. 제거 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
GridFS 데이터베이스에서 파일을 제거합니다.
// from("direct:remove").to("mongodb-gridfs?database=tickets&operation=remove");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
template.requestBodyAndHeaders("direct:remove", "", headers);