내 전자 응용 프로그램의 PouchDB에서 내 문서에 첨부 파일을 추가하려고했습니다. 그러나 마지막 첨부 파일 만 추가 할 수 있으며 이전 파일은 덮어 씁니다.PouchDB 문서에 추가 첨부 파일 추가
다음과 같은 데이터가 새 파일을 추가하는 방식으로 개정되지 않습니다
_attachments":{"someFile.jpg":{"content_type":"image/jpeg","revpos":5,"length":38718,"digest":"md5-X+MOUwdHmNeORSl6xdtZUg=="}
내가 첫 번째 문서를 읽고 다음과 같은 방법으로 여러 첨부 파일을 사용하여 추가 파일 추가 다시해야 :
db.put({
_id: 'mydoc',
_attachments: {
'myattachment1.txt': {
content_type: 'text/plain',
data: blob1
},
'myattachment2.txt': {
content_type: 'text/plain',
data: blob2
},
'myattachment3.txt': {
content_type: 'text/plain',
data: blob3
},
// etc.
}
});
을
?
당신은 내가 하나 개의 문서 (사실은 내가 테스트를 단순화하기 위해 동일한 파일을 두 번 사용하려고)에 두 개의 첨부 파일을 추가 할 수 있는지 확인하기 위해 실행하려고 코드의 일부를 참조하실 수 있습니다 :
pdb.putAttachment(id, name, rev, file, type).then(function (result) {
console.log("att saved:");
console.log(result);
}).catch(function (err) {
console.log(err);
});
var newFileName = "new" + name;
pdb.putAttachment(id, newFileName, rev, file, type).then(function (result) {
console.log("att saved 2:");
console.log(result);
}).catch(function (err) {
console.log(err);
});
을 결과는 : 그것은 보이는
Object {ok: true, id: "1489351796004", rev: "28-a4c41eff6fbdde8a722a920c9d5a1390"}
id
:
"1489351796004"
ok
:
true
rev
:
"28-a4c41eff6fbdde8a722a920c9d5a1390"
CustomPouchError {status: 409, name: "conflict", message: "Document update conflict", error: true, id: "1489351796004"}
error
:
true
id
:
"1489351796004"
message
:
"Document update conflict"
name
:
"conflict"
status
:
409
내가 뭔가를 이해하지 못하거나 내가 제대로 putAttachment를 사용하는 방법을 모르겠어요.
또한 추가 할 것을 SQLite는 데이터가 (기준 시퀀스 테이블, JSON 행)과 같은 방법 :
{...,"_attachments":{"testPicture.jpg":{"content_type":"image/jpeg","revpos":34,"length":357677,"digest":"md5-Bjqd6RHsvlCsDkBKe0r7bg=="}}}
여기서 문제는 구조에 다른 첨부 파일을 추가하는 방법입니다. 어쨌든 나는 putAttachment를 통해이를 달성 할 수 없다.
작동 중입니다. 고맙습니다. 다음 단계는 추가 할 파일 수를 예측할 수 없을 때 상황을 채택하기 위해 제시 한 내용을 수정하는 것입니다 (위의 코드는 첨부 파일 두 개만 추가 함). 광범위한 컨텍스트는 이전에 추가 한 내용을 저장하면서 첨부 파일을 하나씩 추가하는 Electron의 웹 양식을 기반으로합니다. – Lormitto
첨부 파일 배열이있는 경우이 파일을 축소 할 수 있습니다. 이것은 좀 더 진보 된 약속의 물건입니다. [우수한 Promise Anti-Patterns 기사] (http://taoofcode.net/promise-anti-patterns/#the-collection-kerfuffle:8f173b15e2d19515fdc8ce931ae539c0)에있는 정보는 단락의 세 번째 예를 참조하십시오. 더 많은 도움이 필요하면 핑 (ping)!좀 더 알기 쉽게 [async/await] (https://ponyfoo.com/articles/understanding-javascript-async-await)를 사용할 수도 있습니다. 전자에서 지원되는지 확실하지 않지만 [babel] (http://babeljs.io/)을 사용하여 ES5 코드로 변환 할 수도 있습니다. –