How to Add and Remove attachments using MIME
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to remove an attachment that was previously added using MIME.
this is my code
try{
var d = database.getView("Main").getFirstDocument()
var it = d.getFirstItem("Body")
var att:NotesEmbeddedObject = it.getEmbeddedObject("mydoc.docx")
var streamDOC:NotesStream = session.createStream()
streamDOC.setContents(att.getInputStream())
var newd;
newd = database.getView("NewD").getFirstDocument()
if(newd==null){
newd = database.createDocument()
newd.replaceItemValue("Form","Main")
var me = newd.createMIMEEntity("Body")
}else{
var me = newd.getMIMEEntity("Body")
}
var filename = "test.pdf"
var mc = me.createChildEntity();
var he = mc.createHeader("Content-Disposition")
he.setHeaderVal("attachment; filename="" + filename + """);
he = mc.createHeader("Content-ID");
he.setHeaderVal( "<" + filename + ">" );
mc.setContentFromBytes(streamDOC, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", NotesMIMEEntity.ENC_IDENTITY_8BIT);
newd.save()
print("success")
}catch(e){
print("fail " + e)
}
this is the code I use for deleting the attached files
<xp:repeat id="repeat1" rows="30"
value="#{javascript:@AttachmentNames()}" var="att"
>
<xp:text tagName="p" escape="true" id="computedField1"
value="#{javascript:att}"
>
</xp:text>
<xp:link escape="true" text="Delete" id="link2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete"
>
<xp:this.action><![CDATA[#{javascript:try{
var it:NotesRichTextItem = nd.getDocument().getFirstItem("Body")
var eo:NotesEmbeddedObject = it.getEmbeddedObject(att)
if(eo==null){
print("No attachment found")
}else{
print("att ok")
eo.remove()
nd.save()
}
print("success delete " + e)
}catch(e){
print("fail delete " + e)
}}]]></xp:this.action>
</xp:eventHandler></xp:link>
</xp:repeat>
In ytria my document looks like this
When I try to use the link to remove an attachment I get the following errror
2018-11-22 10:27:48 HTTP JVM: fail delete Error calling method 'getEmbeddedObject(string)' on an object of type 'lotus.domino.local.Item [Static Java Interface Wrapper, lotus.domino.local.Item: lotus.domino.Item]'
this is what my webpage look like
What can be the cause of this
Thanks
Thomas
See also this question
How to Remove MIME attachments correctly
xpages attachment mime embedded-object
add a comment |
I am trying to remove an attachment that was previously added using MIME.
this is my code
try{
var d = database.getView("Main").getFirstDocument()
var it = d.getFirstItem("Body")
var att:NotesEmbeddedObject = it.getEmbeddedObject("mydoc.docx")
var streamDOC:NotesStream = session.createStream()
streamDOC.setContents(att.getInputStream())
var newd;
newd = database.getView("NewD").getFirstDocument()
if(newd==null){
newd = database.createDocument()
newd.replaceItemValue("Form","Main")
var me = newd.createMIMEEntity("Body")
}else{
var me = newd.getMIMEEntity("Body")
}
var filename = "test.pdf"
var mc = me.createChildEntity();
var he = mc.createHeader("Content-Disposition")
he.setHeaderVal("attachment; filename="" + filename + """);
he = mc.createHeader("Content-ID");
he.setHeaderVal( "<" + filename + ">" );
mc.setContentFromBytes(streamDOC, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", NotesMIMEEntity.ENC_IDENTITY_8BIT);
newd.save()
print("success")
}catch(e){
print("fail " + e)
}
this is the code I use for deleting the attached files
<xp:repeat id="repeat1" rows="30"
value="#{javascript:@AttachmentNames()}" var="att"
>
<xp:text tagName="p" escape="true" id="computedField1"
value="#{javascript:att}"
>
</xp:text>
<xp:link escape="true" text="Delete" id="link2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete"
>
<xp:this.action><![CDATA[#{javascript:try{
var it:NotesRichTextItem = nd.getDocument().getFirstItem("Body")
var eo:NotesEmbeddedObject = it.getEmbeddedObject(att)
if(eo==null){
print("No attachment found")
}else{
print("att ok")
eo.remove()
nd.save()
}
print("success delete " + e)
}catch(e){
print("fail delete " + e)
}}]]></xp:this.action>
</xp:eventHandler></xp:link>
</xp:repeat>
In ytria my document looks like this
When I try to use the link to remove an attachment I get the following errror
2018-11-22 10:27:48 HTTP JVM: fail delete Error calling method 'getEmbeddedObject(string)' on an object of type 'lotus.domino.local.Item [Static Java Interface Wrapper, lotus.domino.local.Item: lotus.domino.Item]'
this is what my webpage look like
What can be the cause of this
Thanks
Thomas
See also this question
How to Remove MIME attachments correctly
xpages attachment mime embedded-object
add a comment |
I am trying to remove an attachment that was previously added using MIME.
this is my code
try{
var d = database.getView("Main").getFirstDocument()
var it = d.getFirstItem("Body")
var att:NotesEmbeddedObject = it.getEmbeddedObject("mydoc.docx")
var streamDOC:NotesStream = session.createStream()
streamDOC.setContents(att.getInputStream())
var newd;
newd = database.getView("NewD").getFirstDocument()
if(newd==null){
newd = database.createDocument()
newd.replaceItemValue("Form","Main")
var me = newd.createMIMEEntity("Body")
}else{
var me = newd.getMIMEEntity("Body")
}
var filename = "test.pdf"
var mc = me.createChildEntity();
var he = mc.createHeader("Content-Disposition")
he.setHeaderVal("attachment; filename="" + filename + """);
he = mc.createHeader("Content-ID");
he.setHeaderVal( "<" + filename + ">" );
mc.setContentFromBytes(streamDOC, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", NotesMIMEEntity.ENC_IDENTITY_8BIT);
newd.save()
print("success")
}catch(e){
print("fail " + e)
}
this is the code I use for deleting the attached files
<xp:repeat id="repeat1" rows="30"
value="#{javascript:@AttachmentNames()}" var="att"
>
<xp:text tagName="p" escape="true" id="computedField1"
value="#{javascript:att}"
>
</xp:text>
<xp:link escape="true" text="Delete" id="link2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete"
>
<xp:this.action><![CDATA[#{javascript:try{
var it:NotesRichTextItem = nd.getDocument().getFirstItem("Body")
var eo:NotesEmbeddedObject = it.getEmbeddedObject(att)
if(eo==null){
print("No attachment found")
}else{
print("att ok")
eo.remove()
nd.save()
}
print("success delete " + e)
}catch(e){
print("fail delete " + e)
}}]]></xp:this.action>
</xp:eventHandler></xp:link>
</xp:repeat>
In ytria my document looks like this
When I try to use the link to remove an attachment I get the following errror
2018-11-22 10:27:48 HTTP JVM: fail delete Error calling method 'getEmbeddedObject(string)' on an object of type 'lotus.domino.local.Item [Static Java Interface Wrapper, lotus.domino.local.Item: lotus.domino.Item]'
this is what my webpage look like
What can be the cause of this
Thanks
Thomas
See also this question
How to Remove MIME attachments correctly
xpages attachment mime embedded-object
I am trying to remove an attachment that was previously added using MIME.
this is my code
try{
var d = database.getView("Main").getFirstDocument()
var it = d.getFirstItem("Body")
var att:NotesEmbeddedObject = it.getEmbeddedObject("mydoc.docx")
var streamDOC:NotesStream = session.createStream()
streamDOC.setContents(att.getInputStream())
var newd;
newd = database.getView("NewD").getFirstDocument()
if(newd==null){
newd = database.createDocument()
newd.replaceItemValue("Form","Main")
var me = newd.createMIMEEntity("Body")
}else{
var me = newd.getMIMEEntity("Body")
}
var filename = "test.pdf"
var mc = me.createChildEntity();
var he = mc.createHeader("Content-Disposition")
he.setHeaderVal("attachment; filename="" + filename + """);
he = mc.createHeader("Content-ID");
he.setHeaderVal( "<" + filename + ">" );
mc.setContentFromBytes(streamDOC, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", NotesMIMEEntity.ENC_IDENTITY_8BIT);
newd.save()
print("success")
}catch(e){
print("fail " + e)
}
this is the code I use for deleting the attached files
<xp:repeat id="repeat1" rows="30"
value="#{javascript:@AttachmentNames()}" var="att"
>
<xp:text tagName="p" escape="true" id="computedField1"
value="#{javascript:att}"
>
</xp:text>
<xp:link escape="true" text="Delete" id="link2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete"
>
<xp:this.action><![CDATA[#{javascript:try{
var it:NotesRichTextItem = nd.getDocument().getFirstItem("Body")
var eo:NotesEmbeddedObject = it.getEmbeddedObject(att)
if(eo==null){
print("No attachment found")
}else{
print("att ok")
eo.remove()
nd.save()
}
print("success delete " + e)
}catch(e){
print("fail delete " + e)
}}]]></xp:this.action>
</xp:eventHandler></xp:link>
</xp:repeat>
In ytria my document looks like this
When I try to use the link to remove an attachment I get the following errror
2018-11-22 10:27:48 HTTP JVM: fail delete Error calling method 'getEmbeddedObject(string)' on an object of type 'lotus.domino.local.Item [Static Java Interface Wrapper, lotus.domino.local.Item: lotus.domino.Item]'
this is what my webpage look like
What can be the cause of this
Thanks
Thomas
See also this question
How to Remove MIME attachments correctly
xpages attachment mime embedded-object
xpages attachment mime embedded-object
edited Nov 22 '18 at 12:52
Thomas Adrian
asked Nov 22 '18 at 9:45
Thomas AdrianThomas Adrian
2,50122448
2,50122448
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
getFirstItem
returns a NotesItem, not a NotesRichTextItem. I'm not sure SSJS :NotesRichTextItem
casts the result to a NotesRichTextItem. In Java it would be RichTextItem it = (RichTextItem) nd.getDocument().getFirstItem("Body");
. Adding (RichTextItem)
after the =
makes the API convert the result to that class. Maybe that's also needed in SSJS.
The cast in Java would only work if the item is already composite data, which it’s not here. I think that theDominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.
– Jesse Gallagher
Nov 22 '18 at 11:02
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428014%2fhow-to-add-and-remove-attachments-using-mime%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
getFirstItem
returns a NotesItem, not a NotesRichTextItem. I'm not sure SSJS :NotesRichTextItem
casts the result to a NotesRichTextItem. In Java it would be RichTextItem it = (RichTextItem) nd.getDocument().getFirstItem("Body");
. Adding (RichTextItem)
after the =
makes the API convert the result to that class. Maybe that's also needed in SSJS.
The cast in Java would only work if the item is already composite data, which it’s not here. I think that theDominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.
– Jesse Gallagher
Nov 22 '18 at 11:02
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
add a comment |
getFirstItem
returns a NotesItem, not a NotesRichTextItem. I'm not sure SSJS :NotesRichTextItem
casts the result to a NotesRichTextItem. In Java it would be RichTextItem it = (RichTextItem) nd.getDocument().getFirstItem("Body");
. Adding (RichTextItem)
after the =
makes the API convert the result to that class. Maybe that's also needed in SSJS.
The cast in Java would only work if the item is already composite data, which it’s not here. I think that theDominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.
– Jesse Gallagher
Nov 22 '18 at 11:02
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
add a comment |
getFirstItem
returns a NotesItem, not a NotesRichTextItem. I'm not sure SSJS :NotesRichTextItem
casts the result to a NotesRichTextItem. In Java it would be RichTextItem it = (RichTextItem) nd.getDocument().getFirstItem("Body");
. Adding (RichTextItem)
after the =
makes the API convert the result to that class. Maybe that's also needed in SSJS.
getFirstItem
returns a NotesItem, not a NotesRichTextItem. I'm not sure SSJS :NotesRichTextItem
casts the result to a NotesRichTextItem. In Java it would be RichTextItem it = (RichTextItem) nd.getDocument().getFirstItem("Body");
. Adding (RichTextItem)
after the =
makes the API convert the result to that class. Maybe that's also needed in SSJS.
answered Nov 22 '18 at 10:06
Paul Stephen WithersPaul Stephen Withers
14.4k11131
14.4k11131
The cast in Java would only work if the item is already composite data, which it’s not here. I think that theDominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.
– Jesse Gallagher
Nov 22 '18 at 11:02
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
add a comment |
The cast in Java would only work if the item is already composite data, which it’s not here. I think that theDominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.
– Jesse Gallagher
Nov 22 '18 at 11:02
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
The cast in Java would only work if the item is already composite data, which it’s not here. I think that the
DominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.– Jesse Gallagher
Nov 22 '18 at 11:02
The cast in Java would only work if the item is already composite data, which it’s not here. I think that the
DominoDocument
class used by document data sources has some specialized methods for manipulating attachments in a neutral way.– Jesse Gallagher
Nov 22 '18 at 11:02
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I solved by using var eo = nd.getDocument().getAttachment(att) instead. but now I have another problem., when all attachment is removed all the $File items have been removed but the Body items are still in the document. so when I add a new attachment I get all attachments back
– Thomas Adrian
Nov 22 '18 at 12:40
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
I added a new question about this stackoverflow.com/questions/53431447/…
– Thomas Adrian
Nov 22 '18 at 12:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428014%2fhow-to-add-and-remove-attachments-using-mime%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown