I am trying to integrate a topaz signature pad into my ColdFusion application. I would like to capture the signature from the pad, convert it to format that ColdFusion can show in the browser and save to the disk.
Using their documentation, I am able to retrieve the captured signature in a Hexadecimal format (I think). I am following the documentation found on their site here: Basic Javascript Demo
I have then tries to convert that Hexadecimal to Base64 so that I can write the image to the browser and the disk of the ColdFusion server. However ColdFusion doesn't seem to like my format and throw an error.
Can anybody help me with this??
Here is the code that converts the Hexadecimal string and also tries to make an image out of it.
<cfoutput>
Form Data: #form.sigImageData#<br />
<cfscript>
binaryValue = binaryDecode( form.sigImageData, "hex" );
base64Value = binaryEncode( binaryValue, "base64" );
</cfscript>
Converted Data: #base64Value#<br />
<center>
<cfimage
action="write"
destination="c:\V:\Inetpub\wwwroot\signatures\test.png"
source="#base64Value#"
/>
</center>
</cfoutput>
Javascript Provided By Manufacturer:
<script type="text/javascript">
var Index;
function pluginLoaded()
{
//alert("Plugin loaded!");
}
function onClear()
{
document.getElementById('sigplus').clearSignature();
}
function onSign()
{
document.getElementById('sigplus').tabletState = 1;
document.getElementById('sigplus').captureMode = 1;
Index = setInterval(Refresh, 50);
document.getElementById('sigplus').antiAliasSpotSize = .85;
document.getElementById('sigplus').antiAliasLineScale = .55;
}
function onDone()
{
if(document.getElementById('sigplus').totalPoints==0)
{
alert("Please sign before continuing");
return false;
}
else
{
document.getElementById('sigplus').tabletState = 0;
clearInterval(Index);
//RETURN TOPAZ-FORMAT SIGSTRING
document.getElementById('sigplus').compressionMode=1;
document.SigForm.bioSigData.value=document.getElementById('sigplus').sigString;
document.SigForm.sigStringData.value+=document.getElementById('sigplus').sigString;
//this returns the signature in Topaz's own format, with biometric information
//RETURN BMP BYTE ARRAY CONVERTED TO HEXADECIMAL STRING
document.getElementById('sigplus').imageXSize = 500;
document.getElementById('sigplus').imageYSize = 100;
document.getElementById('sigplus').penWidth = 5;
//SigPlus1.JustifyMode = 5;
var bmpString = '';
document.getElementById('sigplus').bitmapBufferWrite(5);
var bmpSize = document.getElementById('sigplus').bitmapBufferSize();
for(var a = 0; a < bmpSize; a++)
{
var byte = document.getElementById('sigplus').bitmapBufferByte(a).toString(16);
if(byte.length === 1)
{
bmpString += '0';
}
bmpString += byte;
}
document.SigForm.sigImageData.value+=bmpString;
document.SigForm.sigImgData.value=bmpString;
//this example returns a bitmap image converted to a hexadecimal string
//convert the string back to a byte array on the server for final imaging
document.SigForm.submit(); //SUBMIT THE FORM HERE
}
}
function Refresh()
{
document.getElementById('sigplus').refreshEvent();
}
</script>
Here is My ColdFusion Error Output:
The web site you are accessing has experienced an unexpected error. Please contact the website administrator.
The following information is meant for the website developer for debugging purposes. Error Occurred While Processing Request An exception occurred while trying to read the image.
'' The error occurred in C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm: line 29
27 : action="writeToBrowser"
28 : source="#binaryValue#"
29 : isBase64="no">
30 :
31 : </cfoutput> Resources: Check the ColdFusion documentation to verify that you are using the correct syntax. Search the Knowledge Base to find a solution to your problem. Browser Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36 Remote Address 192.168.10.103 Referrer https://jaydien.ezservicetrax.com/serviceticket/sigpad/index.cfm Date/Time 11-Mar-14 03:37 PM Stack Trace at cfaction2ecfm1686568327.runPage(C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm:29)
coldfusion.image.ImageReader$ImageReadingException: An exception occurred while trying to read the image. at coldfusion.image.ImageReader.readImage(ImageReader.java:133) at coldfusion.image.Image.<init>(Image.java:132) at coldfusion.tagext.io.ImageTag.doStartTag(ImageTag.java:401) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2661) at cfaction2ecfm1686568327.runPage(C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm:29) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:483) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:288) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:86) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126) at coldfusion.CfmServlet.service(CfmServlet.java:198) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
(More of a comment, but a bit too long ...)
I tested the sample hex string with CF9 and got the same result. While the file header, and fact that you can open it with MS Paint, suggests it is a bitmap, I am not sure exactly what type/format Topaz is returning. (Skimming the API did not turn up anything pertinent so far)
As a temporary work-around, you could use .net objects. Load the file with System.Drawing.Bitmap and rewrite it to disk. The result should be a bitmap compatible with cfimage. This solution is not ideal, due to the double write. However, it is an interim option, while you investigate the returned format further.
<cfscript>
// decode hex and save binary to file
binaryData = binaryDecode(orm.sigImageData, "hex");
saveToPath = "c:/temp/original.bmp";
fileWrite(saveToPath, binaryData);
// load and resave with .net
Bitmap = createObject(".net", "System.Drawing.Bitmap").init(saveToPath);
Bitmap.Save("c:/temp/new.bmp");
// .. cleanup
</cfscript>
<!--- display new image --->
<cfimage action="writeToBrowser" source="c:/temp/new.bmp" />
Building off of Leigh's suggestion, I have also found that his previous suggestion of just using FileWrite to save the decoded hex string to disk as a BMP and then displaying it on screen using the <IMG> tag is a usable workaround as well. Either way, I am able to get something in place in the meantime.
<cfset binaryValue = binaryDecode( form.sigImageData, "hex" )>
<cfset FileWrite("c:\Inetpub\wwwroot\signatures\test.bmp", binaryValue)>
<img src="/siguatures/test.bmp">
Related
I have a new CF18 server and I'm getting some errors reading and converting some old images that were readable on my previous CF11 server. FYI GetReadableImageFormats results in "BMP,GIF,JPEG,JPEG 2000,JPEG2000,JPG,PNG,PNM,RAW,TIF,TIFF,WBMP"
Normally I read the files as a Binary and put it into memory for manipulation
<cffile action="readBinary" file="#file_location#" variable="binImage" />
<cfimage action="read" source="#binImage#" name="objImage" isbase64="no">
This now results in an error:
"An exception occurred while trying to read the image. No SOF segment in stream"
Reading the file with action="read" and dumping the left(binImage, 999) results:
"...2015:10:07 17:46:58 Kofax standard Multi-Page TIFF Storage Filter v3.03.000,..."
Then I tried reading it into java using:
<cfset tifFileName="#file_location#">
<cfscript>
ss = createObject("Java","com.sun.media.jai.codec.FileSeekableStream").init(tifFileName);
//create JAI ImageDecoder
decoder = createObject("Java","com.sun.media.jai.codec.ImageCodec").createImageDecoder("tiff", ss, JavaCast("null",""));
</cfscript>
Which yields an error:
"Decoding of old style JPEG-in-TIFF data is not supported."
I found this...
Decoding of old style JPEG-in-TIFF data is not supported
Do you think using TwelveMonkeys ImageIO the best path to follow for my issue?
UPDATE: Based on the suggestion that there is an invalid marker 0xFF9E I tried the following:
<cffile action="readBinary" file="#file_location#" variable="binImage" />
<cfset hexEncoding = binaryEncode(binImage, "hex")>
<cfset new_hexEncoding = replaceNoCase(hexEncoding, 'FF9E', 'FFE9', 'ALL')>
<cfset binImage = binaryDecode(new_hexEncoding, "hex")>
isImage(binImage) returns "NO" and the "No SOF segment in stream" error persists. I looped over the hexEncoding and found the FF9E string 23x. I've never edited raw image code so I'm not sure my replace is correct.
Edit: At this point I'm fairly certain my Search and Replace hexEncoding, 'FF9E', 'FFE9' logic is flawed. there is no occurance of 0xff9e in the binaryEncoded binImage.
This was driving me nuts. I tried everything I could find short of installing extra JAVA libraries or routing it through other executables to make the conversion. In my case there is only one JPEG in a TIFF, so I wrote something that literally grabs the binary data for the JPEG out of the TIFF (doesn't account for pages) and serves it up. Once you have the binary of the JPEG you can write it to a file, do conversions on it, even stream it direct to the browser. Here ya go future people who need this. I didn't write it to do pages or detect what kind of tiff it is since for my uses I already know all that. These things are .bin files, but they are all the same single page jpeg in a tiff and I needed a way to serve them up quickly in a format that browsers don't hate. This runs fast enough to be served up on the fly. Is there a better way? Probably, but this works, self contained, copy and paste, and makes complete sense to anyone that needs to edit it.
<cfscript>
strFileName = "test.tiff";
blnOutputImageToBrowser = true;
blnSaveToFile = true;
strSaveFile = GetDirectoryFromPath(GetCurrentTemplatePath())&"test.jpg"
imgByteArray = FileReadBinary(strFileName);
//Convert to HEX String
hexString = binaryEncode(imgByteArray,"hex"); //Convert binary to HEX String, so we can pattern search it
//Set HEX Length
hexLength = arraylen(imgByteArray);
//Find Start of JPG Data in HEX String
jpegStartHEX = find("FFD8FF",hexString);
jpegStartBIN = (jpegStartHEX-1)/2; //-1 because CF arrays start on 1 and everyone else starts on 1. /2 because the HEX string positions are double the byte array positions
objByteBuffer = CreateObject("java","java.nio.ByteBuffer"); //Init JAVA byte buffer class for us to use later (this makes it go faster than trying to convert the hex string back to binary)
//Find Stop of JPG Data
jpegStopHEX = 0;
jpegStopBIN = 0;
intSearchIDX = jpegStartHEX+6; //Might as well start after the JPEG start block
blnStop = false;
while (intSearchIDX < len(hexString) && jpegStopHEX == 0 && !blnStop) {
newIDX = find("FFD9",hexString,intSearchIDX);
if (newIDX == 0) {
blnStop=true;
}
else {
if (newIDX%2 == 0) { //bad search try again (due to indexing in CF starting on 1 instead of 0, the even numbers are in between hex code [they are pairs like 00 and FF])
intSearchIDX = newIDX+1;
}
else { //Found ya
jpegStopHEX = newIDX;
blnStop=true;
}
}
}
jpegStopBIN = (jpegStopHEX-1)/2; //-1 because CF arrays start on 1 and everyone else starts on 1. /2 because the HEX string positions are double the byte array positions
//Dump JPG Binary into ByteArray from the start and stop positions we discovered
jpegLengthBIN = jpegStopBIN+2-jpegStartBIN;
objBufferImage = objByteBuffer.Allocate(JavaCast( "int", jpegLengthBIN ));
objBufferImage.Put(imgByteArray,JavaCast( "int", jpegStartBIN ),JavaCast( "int", jpegLengthBIN ));
if (blnSaveToFile) { //Dump byte array into test file
fileWrite(strSaveFile,objBufferImage.Array());
}
if (blnOutputImageToBrowser) {
img = ImageNew( objBufferImage.Array() );
ImageResize(img,"1200","","highestPerformance"); //Because we might as well show an example of resizing
outputImage(toBinary(toBase64(img))); //You could skip loading the byte array as an image object and just plop the binary in directly if you don't need to manipulate it any
}
</cfscript>
<cffunction name="outputImage" returntype="void">
<cfargument name="binInput" type="binary">
<cfcontent variable="#binInput#" type="image/png" reset="true" />
<cfreturn>
</cffunction>
I am using ColdFusion 10.
When trying to read some image files, ColdFusion returns no values and no error messages are shown.
I tried to re-size an image using cfimage tag. It is crashing. So I tried to get info about the image using "imageinfo" function. It returns blank. Please help me to either get some info or skip the image. Can anyone help me?
I tried reading the file which caused the anomaly using
<cfimage action="read" source="full pathname" name="image">
<cfset image = imageRead(full pathname)>
and many other ColdFusion documented functions. No error was shown. No output was obtained. I used cffile which showed unsupported file type error.
<cffile
action = "readBinary" file = "full pathname" variable = "variable name"
>
Thanks Rino
Try using this function for reading images.
<cfimage> tag or imageNew() can have issues while trying to read image files which are corrupted or files saved with changed extensions (background transparent .png files saved as .jpeg) while uploading.
I think the main problem with these files is that there is a chance coldfusion doesn't throw an error of any sort when we try to read files mentioned above.
<cfscript>
public function readImage(fullpath){
//trying java imageio
var imageFile = createObject("java", "java.io.File").init(fullpath);
// read the image into a BufferedImage
var ImageIO = createObject("java", "javax.imageio.ImageIO");
try {
var bi = ImageIO.read(imageFile);
return ImageNew(bi);
} catch(any e) {
//try for bad formatted images
//create java file object, passing in path to image
var imageFile = createObject("java","java.io.File").init(fullpath);
//create a FileSeekableStream, passing in the image file we created
var fss = createObject("java","com.sun.media.jai.codec.FileSeekableStream").init(imageFile);
//create ParameterBlock object and initialize it (call constructor)
var pb = createObject("java","java.awt.image.renderable.ParameterBlock").init();
//create JAI object that will ultimately do the magic we need
var JAI = createObject("java","javax.media.jai.JAI");
try {
//pass in FileSeekableStream
pb.add(fss);
//use the JAI object to create a buffered jpeg image.
var buffImage = local.JAI.create("jpeg", pb).getAsBufferedImage();
//pass the buffered image to the ColdFusion imagenew()
var New_Image = imagenew(buffImage);
//make sure we close the stream
fss.close();
return New_Image;
} catch (any e) {
if (isDefined("fss")) {
fss.close();
}
rethrow;
}
}
}
</cfscript>
I am trying to parametrise web service requests in a web performance test. Using Fiddler2 I have recorded a sequence of over 60 web service requests for a transaction performed by my desktop application and saved them as a .webtest file. This web test runs without any errors and the responses that I have checked look correct.
When the web service requests are viewed in Visual Studio 2012 they appear in plain text and so I should be able to edit them to parametrise the values in the SOAP requests. For example, most of the requests contain the text <Database>db1a</Database> (actually it has <Database>db1a</Database>) and I want to change them to get the database name from a context parameter. There are several other items to replace with parameters. For this one transaction there are over 60 web service requests and I have other transactions to record. The .webtest file contains XML and the requests looks like:
<Request Method="POST" Version="1.1" Url="http://example.com/somewhere.asmx" ThinkTime="83" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Content-Type" Value="text/xml; charset=utf-8" />
<Header Name="SOAPAction" Value=""http://example.com/webservices/VariousActionNamesHere"" />
</Headers>
<StringHttpBody ContentType="text/xml; charset=utf-8">PAA/AHgAbQBsACAAdg
... lots more characters not shown
+AA==</StringHttpBody>
</Request>
The StringHttpBody field contains an encoded version of the SOAP request. Visual Studio shows it as plain text. What is the encoding of this field and how can I decode and encode it?
I have installed Release 3.0 of the “Web and Load Test Plugins for Visual Studio Team Test” from http://teamtestplugins.codeplex.com/ . They provide a slightly better interface for editing the SOAP requests one at a time. But they do not allow mass changes.
Converting the web test to a coded web test (ie into C#) shows the SOAP requests as simple text and they could be edited there but I would prefer to keep the flexibility of a .webtest file.
Update: I have posted a partial answer to the question. Whilst it works, it feels the wrong way to do the work because it feels too complicated. So I am looking for a better overall approach.
StringHttpBody is base64 encoded. The raw body of the request is converted to a UTF-16 byte array and then base64 encoded, like so:
Convert.ToBase64String(Encoding.Unicode.GetBytes(oSession.GetRequestBodyAsString()));
For a quick view, you can copy/paste this string into Fiddler's Tools > TextWizard screen then use the From Base64 option to decode.
Here is part of an answer to working with the StringHttpBody fields. This is about decoding and encoding the fields to allow easier understanding and modification.
Read the input XML and find the contents of the StringHttpBody fields. Replace each field contents with the result of calling the following routine on the original contents. Write the all the lines to a new intermediate file. The byte array contains UTF-16 characters as high and low bytes. (All the characters I have seen so far have high byte zero.)
private string DecodeBody(string source) {
byte[] outBytes = Convert.FromBase64String(source);
StringBuilder sb = new StringBuilder();
Assert( (outBytes.Length % 2) != 0 );
for (int ix = 0; ix < outBytes.Length; ix += 2) {
Assert(outBytes[ix] != 0);
sb.Append((char)outBytes[ix + 1]);
}
return sb.ToString();
}
Now have a file containing a simple text version of the .webtest file. This file can easily be edited to parameterise fields of the requests. Have an routine used similar to the one above and writing to another intermediate file. The routine has statements such as:
source = source.Replace("<Database>db1a</Database>", "<Database>{{DatabaseName}}</Database>");
The final intermediate file is then reencoded to create a new .webtest file. Just as before the contents of the StringHttpBody fields are found and replaced with the result of calling a routine. The encoding routine is:
private string EncodeBody(string source) {
StringBuilder sb = new StringBuilder();
byte[] outBytes = new byte[2 * source.Length];
for (int ix = 0; ix < source.Length; ix++) {
char ch = source[ix];
outBytes[2 * ix] = (byte)(((int)ch) & 0xFF);
outBytes[2 * ix + 1] = (byte)((((int)ch) / 256) & 0xFF);
}
sb.Append(Convert.ToBase64String(outBytes));
return sb.ToString();
}
The flow of files is thus:
decode original.webtest > intermediate1
parameterise intermediate1 > intermediate2
encode intermediate2 > final.webtest
On the small number of .webtest files I have tried the encode operation is the inverse of the decode operation, the original file from before decoding is identical to the file after encoding. Having the two intermediate files allows easy checking and searching of the contents of the unencoded file and the effect of the parameterise step.
For
[StringHttpBody ContentType="application/json"]
To Decode the body:
var encodedString = childNode.InnerText;
var encodedStringBytes = Convert.FromBase64String(encodedString);
var decodedString = Encoding.Unicode.GetString(encodedStringBytes);
JObject jsonString =JsonConvert.DeserializeObject(decodedString);
To Encode the body:
childNode.InnerText =
Convert.ToBase64String(Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(jsonString)));
I think this might help.
Im using Amazon CloudSearch as source to a JQuery Autocomplete select. It works very well, but for a reason that I`m not able to identify, when only one result is returned the encoding becomes a mess.
The solution works as follows:
Text input where people type neighborhoods or streets of a given city:
<div id="searchFormContainer">
<input type="text" value=" Digite o bairro ou rua" name="inputSearch" id="inputSearch"/>
</div>
JQuery autocomplete config:
var sourceFunction = function (request, response) {
var successFunction = function (places) {
var placesWithLabel = jQuery.map(places, function (place) {
var label = (place.addressName) ? place.addressName+', ' : '';
label += place.neighborhoodName;
var value = label;
return {label:label, value:value};
});
if(placesWithLabel.length==0){
placesWithLabel.push({label:"Não encontrado", value:""})
}
response(placesWithLabel);
}
var ajaxOptions = {appendTo: '#searchFormContainer',
url: '/textSearch', dataType: "json",
data: {strToSearch: request.term,
cityName: self.place.city.name},
success: successFunction};
jQuery.ajax(ajaxOptions);
};
var openFunction = function () {
jQuery(this).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
};
var closeFunction = function () {
jQuery( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
};
var selectFunction = function (event, data) {
if(data.item.value==""){
return;
}else{
//redirect to result page
}
};
**var autocompleteOptions = {appendTo: '#searchFormContainer',
source: sourceFunction,
minLength: 1,
open: openFunction,
close: closeFunction,
select: selectFunction};**
**$('#searchFormContainer #inputSearch').autocomplete(autocompleteOptions);**
It works successfully, calling my python view named textSearch, which does:
def textSearch(request):
results = simplejson.loads(requests.get('http://%s/2011-02-01/search?' % (settings.SEARCH_CLOUD_HOST), params=fieldsParameter).text)['hits']
return HttpResponse(simplejson.dumps(results), mimetype='application/json')
Taking for example a search for the street named Oscar Freire in neighbourhood Cerqueira César, when I type Oscar Fr in the autocomplete, Amazon CloudSearch returns me two results:
[16/Apr/2013 23:59:47] "GET /textSearch?strToSearch=Oscar+F&cityName=S%C3%A3o+Paulo HTTP/1.1" 200 682
Neighbourhood from Amazon --> Cerqueira César
Returns from Amazon --> {'id_address': u'52267', 'neighborhoodName': u'Cerqueira C\xe9sar', 'addressName': u'Rua Oscar Freire', 'id_neighborhood': u'19694'}
Neighbourhood from Amazon --> Jardim Anália Franco
Returns from Amazon --> {'id_address': u'61073', 'neighborhoodName': u'Jardim An\xe1lia Franco', 'addressName': u'Rua Jos\xe9 Oscar Abreu Sampaio', 'id_neighborhood': u'19881'}
But, typing one more letter with the search keyword Oscar Fre, which returns only one result I`ve:
[16/Apr/2013 23:59:49] "GET /textSearch?strToSearch=Oscar+Fr&cityName=S%C3%A3o+Paulo HTTP/1.1" 200 286
Neighbourhood from Amazon --> Cerqueira CĂŠsar
Returns from Amazon --> {'id_address': u'52267', 'neighborhoodName': u'Cerqueira C\u0102\u0160sar', 'addressName': u'Rua Oscar Freire', 'id_neighborhood': u'19694'}
As we can see in the output, the returned object is the same (id_address is the same for both results). The amazon object (RAW JSON extracted from CloudSearch) for this entry is:
{"rank":"-text_relevance","match-expr":"(label 'Oscar Freire')","hits":{"found":1,"start":0,"hit":[{"id":"52267","data":{"address":["Rua Oscar Freire"],"bairro":["Cerqueira César"],"fieldtype":["address"],"id_address":["52267"],"id_neighborhood":["19694"],"latitude":["-23.568315"],"longitude":["-46.66293"],"text_relevance":["310"]}}]},"info":{"rid":"e2467862eecf73","time-ms":3,"cpu-time-ms":0}}
For me is clear the fact that the response is coming with wrong encoding to my python view.. But I can`t realize where this problem begins. If it is a bad behaviour from JQuery autocomplete or a problem with Amazon response. Any ideas?
Best Regards
I think it's important to isolate the possible causes of the issue. There are too many possible sources of encoding problems here, you should start with removing possible sources of problems.
If you search for "Oscar Fr" vs. "Oscar F" in a browser (using the CloudSearch search endpoint), does the encoding change at all? If it stays the same, then the problem is not CloudSearch, and you can move up the stack.
I need an example for adding events to my calendars through emails. For example when I send an email to my clients regarding their appointment, i want them to have an option in the email that will allow them to add the event on their calendar by just clicking on a button or something.
Is there anything out there that someone can direct me to it?
I need this mainly to use it with coldfusion 9.
Thanks!
I'd recommend the iCalUs UDF from http://www.cflib.org/udf/icalus
WebDH provides a great example here.
Here's an example using CF9 that I quickly put together but haven't tested yet.
<cfscript>
eventStr = {};
eventStr.organizerName = "John Doe"; //Organizer Name
eventStr.organizerEmail = "john.doe#email.com"; //Organizer Email
eventStr.startTime = ParseDateTime("12/30/2011 11:00"); //format: m/d/yyyy HH:mm OR h:mm TT -- this is Eastern time
eventStr.subject = "Demo Example";
eventStr.location = "StackOverflow.com";
eventStr.description = "Example iCalendar using CF9";
// Display in browser
//pc = getpagecontext().getresponse();
//pc.getresponse().setcontenttype('text/calendar');
//pc.setHeader("Content-Disposition","inline;filename=newAppointment.ics");
//writeOutput(iCalUS(eventStr));
//Email
m = new mail();
m.setSubject( "Event" );
m.setTo( "user#email.com" );
m.setFrom( "me#email.com" );
m.setServer( "localhost" );
//m.addParam( file="#ACCOUNT_TXT_FILE#" );
m.addPart( type="text", charset="utf-8", wraptext="72", body="Attached is a calendar event..." );
m.addPart( type="text/calendar" body="#iCalUS(eventStr)#");
m.send();
</cfscript>
Here's another example reference that shows how to email the calendar event.
Here is a very basic implementation of the ICS format. This is designed to be accessed through a browser, but it'd be fairly academic to change to create a text file with ICS extension and send it via e-mail.
<cfheader name="Content-Disposition" value="attachment; filename=event.ics" />
<cfcontent reset="true" type="text/calendar" />
<cfscript>
// handle all-day events
if (NOT isDate(starttime) OR NOT isDate(endtime)) {
dtstart=';VALUE=DATE:#dateFormat(eventdate,"yyyymmdd")#';
dtend=';VALUE=DATE:#dateFormat(dateAdd("d",1,eventdate),"yyyymmdd")#';
} else {
dtstart=';TZID="Eastern Standard Time":#dateFormat(eventdate,"yyyymmdd")#T#timeFormat(starttime,"HHmmss")#';
dtend=';TZID="Eastern Standard Time":#dateFormat(eventdate,"yyyymmdd")#T#timeFormat(endtime,"HHmmss")#';
}
</cfscript>
<cfoutput>
BEGIN:VCALENDAR
PRODID:-//Company//Source//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
BEGIN:STANDARD
DTSTART:16011104T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010311T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:#dateFormat(dateAdded,"yyyymmdd")#T#timeFormat(dateAdded,"HHmmss")#Z
DESCRIPTION:#desc#
DTEND#dtend#
DTSTAMP:#dateFormat(dateAdded,"yyyymmdd")#T#timeFormat(dateAdded,"HHmmss")#Z
DTSTART#dtstart#
LAST-MODIFIED:#dateFormat(dateApproved,"yyyymmdd")#T#timeFormat(dateApproved,"HHmmss")#Z
LOCATION:#location#
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=en-us:#title#
TRANSP:OPAQUE
UID:#dateFormat(now(),"yyyymmdd")#T#timeFormat(now(),"HHmmss")#Z##uniqueID#
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR
</cfoutput>