I use the following code to attach attachment with the document.
doc = [database documentWithID: @“TestDocID”];
CBLUnsavedRevision* newRev = [doc.currentRevision createRevision];
UIImage photo = [UIImage imageNamed:@“storepicture.jpg”];
NSData imageData = UIImageJPEGRepresentation(photo, 0.75);
[newRev setAttachmentNamed: @"storepicture.jpg"
It works fine, this attaches the attachment and push to server. I have 2 questions.
- it is creating always new revision of the existing document. Is it possible to use the previous revision of the document and just attach the attachment alone?
- Where will be this attachment saved on the server or sync gateway after pushing from iOS App? what is the path over there? I can access this attachment using Rest API’s, no problem, But i want to know in which path these attachment files will be stored on the backend server or sync gateway?
No, the attachment is part of the revision, so to change an attachment you have to create a revision.
Could you please explain about changing the attachment? My concern was, just pushing an attachment for the existing document, not like changing the attachment.
Are you saying that my code in the original post does work perfectly, i mean it has to create new revision like that every time when we attach an attachment with the existing document?
Yes, you need to create a new revision every time you add an attachment. You’re making a change, so that has to be tracked as a new revision.
Nothing is persisted on Sync Gateway normally. There’s no path to your attachment. On Couchbase Server it’s stored in the database bucket. You should not count on knowing internals there.
What are you trying to achieve by knowing the attachment location? We might be able to give you more help if you can describe the goal.
Yes, your code is correct.
Revisions are immutable by design. (The revision ID includes a digest of the contents of the revision.) The replicator depends on this.
Making any change to a document, including the identity/contents of attachments, requires creating a new revision.
In other words, what you’re asking is very much like “why can’t I change a file in a Git repository without creating a new commit?”