How to insert image into lightning-input-rich-text programmatically? - salesforce

I have an image in base64 format and I want to push the image data explicitly into my lightning-input-rich-text. Is there any way?
My code looks like this:
<lightning-input-rich-text value={body} label="EmailBody" placeholder="Email Body" >
</lightning-input-rich-text>
and in my JS Controller I am trying to do this
this.body = this.filesUploaded[0]['VersionData']
// this.filesUploaded[0]['VersionData'] represent the base64 format data
Instead of showing the image My lightning-input-rich-text show base64 string for ex: ('iVBORw0KGgoAAAA....')

You would need to make sure your are adding an IMG html tag to the contents of your rich text control. So, in your js file, your body variable must be set to a string that represents the html code needed to create an IMG tag that uses base64 as its source, e.g.:
this.body = '<img src="data:image/png;base64,' + this.filesUploaded[0]['VersionData'] + '" />';

Related

IronPDF html query parameter

Does IronPDF support html query parameters, or is there an alternate method?
I've been using IronPDF to convert an html file to PDF using the following method: var pdf = ironRenderer.RenderUrlAsPdf(reportPath);
However, the html located at reportPath now requires a parameter userid. I have tried var pdf = ironRenderer.RenderUrlAsPdf(reportPath?userid=1); but that gives me the following error: CheckHtmlFilePath - File not found: .../index.html%3Fuserid=1'
I can't see any documentation in IronPdf that parameters are supported. Does anyone have any work arounds?
Instead of adding the parameter to the variable name, add it to the string. For example:
reportPath += "?userid=1";
var pdf = ironRenderer.RenderUrlAsPdf(reportPath);
Check the URL to see if there is already a parameter, and manipulate the URL string accordingly. If you posted more code I could have described more.

How to use object url in audio src

I am making a audio player using
<audio src={audioSrc}>
tag.
When I get the audio file, it was a binary file(blob below) so I created a blob with it.
let test = new Blob(blob, {type: 'audio/mp3'};
And then created an object url
let objUrl = URL.createObjectURL(test);
This objUrl looks like blob:https://xxxxx and when I pass this string to <audio src={objUrl}/>, I cannot hear anything.
I was wondering if I have to convert this url to make it available in audio tag.
Can I get an advice for this problem please?
The first parameter of the Blob constructor is an array. MDN describes it like this:
An Array of ArrayBuffer, ArrayBufferView, Blob, USVString objects, or a mix of any of such objects, that will be put inside the Blob. USVString objects are encoded as UTF-8.
https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters
Maybe creating your blob like this already solves the problem:
let test = new Blob([ blob ], { type: 'audio/mp3' });
Another problem I could think of is that the binary data has a different mimeType other than 'audio/mp3' which could cause the audio element to give up decoding the data.
Just add another prop autoplay
<audio src={URL.createObjectURL(test)} autoplay/>

Movilizer - changing name of captured image

In my scenario I'm using the image capture screen for taking photos of specific machines.
In the replies the name of the images is 1427726930.jpg
Can this name be changed I'd like to have a prefix like:
UIDxxxxxxTSxxxxxx.jpg
It is possible to override the auto generated name in the image capture screen, by calling setAnswerValue on the Answer that contains the image after capturing.
For your scenario this can look as follows:
<question key="#1" type="10" title="">
<answer key="#1_1" nextQuestionKey="END"/>
<onLeaveOkPersistAssignment>
init = getAnswerValue($answer:'#1_1');
renamed = conCat('ID', getUserId(), '-', init);
setAnswerValue($answer:'#1_1', renamed);
newName = getAnswerValue($answer:'#1_1');
</onLeaveOkPersistAssignment>
</question>
calling getAnswerValue returns the auto generated name which is a numeric timestamp followed by the file extension. This is practically the part of your pattern after the TS. So all you have to do is to retrieve the participant ID and to concatenate everything in the right order.

View HTML Email in WPF Webbrowser

In my application I send HTML Email receipts to customers after finishing an order. What I would like to do is preview this in a webbrowser control.
The code I have works fine, but the images are missing in the browser.
I create the HTML in an AlternateView like this:
Dim hview As AlternateView = AlternateView.CreateAlternateViewFromString(ReadTemplate(order), Nothing, "text/html")
Then loop through the images they ordered and add them like this:
Dim M As New LinkedResource(ResizeAndRotate(I.Path), Net.Mime.MediaTypeNames.Image.Jpeg) With {.ContentId = "Main" & cnt}
hview.LinkedResources.Add(M)
Then return a document from the hview stream:
Dim ObjDoc As New HTMLDocument
Dim Doc As IHTMLDocument2 = ObjDoc
Dim reader As New IO.StreamReader(hview.ContentStream)
Doc.write(reader.ReadToEnd)
Return ObjDoc
How would I also get the images from the stream?
I don't believe that you can use images from memory. You'll need to save them to the hard drive, even temporarily. The you have to reference them in your HTML something like this:
<img alt="An image" src="file:///C:/Images/Image.jpg" width="400" height="400" />
You can encode your image data with base64 and embed it inline on the page, as supported with Data URI scheme. Example:
<!-- http://en.wikipedia.org/wiki/Data_URI_scheme -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg=="/>
Of course, that would add some overhead to the page size, which may by substantial, depending on the original image size.

How to export Rich Text fields as HTML from Notes with LotusScript?

I'm working on a data migration task, where I have to export a somewhat large Lotus Notes application into a blogging platform. My first task was to export the articles from Lotus Notes into CSV files.
I created a Agent in LotusScript to export the data into CSV files. I use a modified version of this IBM DeveloperWorks forum post. And it basically does the job. But the contents of the Rich Text field is stripped of any formatting. And this is not what I want, I want the Rich Text field rendered as HTML.
The documentation for the GetItemValue method explicitly states that the text is rendered into plain text. So I began to research for something that would retrieve the HTML. I found the NotesMIMEEntity class and some sample code in the IBM article How To Access HTML in a Rich Text Field Using LotusScript.
But for the technique described in the above article to work, the Rich Text field need to have the property "Store Contents as HTML and MIME". And this is not the case with my Lotus Notes database. I tried to set the property on the fields in question, but it didn't do the trick.
Is it possible to use the NotesMIMEEntity and set the "Store Contents as HTML and MIME" property after the content has been added, to export the field rendered as HTML?
Or what are my options for exporting the Notes database Rich Text fields as HTML?
Bonus information: I'm using IBM Lotus Domino Designer version 8.5
There is this fairly unknown command that does exactly what you want: retrieve the URL using the command OpenField.
Example that converts only the Body-field:
http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField
Here is how I did it, using the OpenField command, see D.Bugger's post above
Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String
Dim obj
Set obj = CreateObject("Microsoft.XMLHTTP")
obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", ""
obj.send("")
Dim html As String
html = Trim$(obj.responseText)
GetHtmlFromField = html
End Function
I'd suggest looking at Midas' Rich Text LSX (http://www.geniisoft.com/showcase.nsf/MidasLSX)
I haven't used the personally, but I remember them from years ago being the best option for working with Rich Text. I'd bet it saves you a lot of headaches.
As for the NotesMIMEEntity class, I don't believe there is a way to convert RichText to MIME, only MIME to RichText (or retain the MIME within the document for emailing purposes).
If you upgrade to Notes Domino 8.5.1 then you can use the new ConvertToMIME method of the NotesDocument class. See the docs. This should do what you want.
Alternativly the easiest way to get the Domino server to render the RichText will be to actually retrieve it via a url call. Set up a simple form that just has the RichText field and then use your favourite HTTP api to pull in the page. It should then be pretty straight forward to pull out the body.
Keep it simple.
Change the BODY field to Store contents as HTML and MIME
Open the doc in editmode.
Save.
Close.
You can now use the NotesMIMEEntity to get what you need from script.
You can use the NotesDXLExporter class to export the Rich Text and use an XSLT to transform the output to what you need.
I know you mentioned using LotusScript, but if you don't mind writing a small Java agent (in the Notes client), this can be done fairly easily - and there is no need to modify the existing form design.
The basic idea is to have your Java code open a particular document through a localhost http request (which is simple in Java) and to have your code capture that html output and save it back to that document. You basically allow the Domino rendering engine to do the heavy lifting.
You would want do this:
Create a form which contains only the rich-text field you want to convert, and with Content Type of HTML
Create a view with a selection formula for all of the documents you want to convert, and with a form formula which computes to the new form
Create the Java agent which just walks your view, and for each document gets its docid, opens a URL in the form http://SERVER/your_database_path.nsf/NEW_VIEW/docid?openDocument, grabs the http response and saves it.
I put up some sample code in a similar SO post here:
How to convert text and rich text fields in a document to html using lotusscript?
Works in Domino 10 (have not tested with 9)
HTMLStrings$ = NotesRichTextItem .Converttohtml([options] ) As String
See documentation :
https://help.hcltechsw.com/dom_designer/10.0.1/basic/H_CONVERTOHTML_METHOD_NOTESRICHTEXTITEM.html
UPDATE (2022)
HCL no longer support this method since version 11. The documentation does not include any info about the method.
I have made some tests and it still works in v12 but HCL recommended to not use it.
Casper's recommendation above works well, but make sure the ACL is such to allow Anonymous Access otherwise your HTML will be the HTML from your login form
If you do not need to get the Richtext from the items specifically, you can use ?OpenDocument, which is documented (at least) here: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/
https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html
OpenDocument also allows you to expand sections (I am unsure if OpenField does)
Syntax is:
http://Host/Database/View/DocumentUniversalID?OpenDocument
But be sure to include the charset parameter as well - Japanese documents were unreadable without specifying utf-8 as the charset.
Here is the method I use that takes a NotesDocument and returns the HTML for the doc as a string.
private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null)
{
var server = doc.ParentDatabase.Server.Split('/')[0];
var dbPath = doc.ParentDatabase.FilePath;
string viewName = "0";
string documentId = doc.UniversalID.ToUpper();
var ub = new UriBuilder();
ub.Host = server;
ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId;
if (string.IsNullOrEmpty(sectionList))
{
ub.Query = "OpenDocument&charset=utf-8";
}
else
{
ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList;
}
var url = ub.ToString();
var req = HttpWebRequest.CreateHttp(url);
try
{
var resp = req.GetResponse();
string respText = null;
using (var sr = new StreamReader(resp.GetResponseStream()))
{
respText = sr.ReadToEnd();
}
return respText;
}
catch (WebException ex)
{
return "";
}
}

Resources