EasyCFM.COM ColdFusion Forums / Coding Help! / integrating a cf upload into nicEdit

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: integrating a cf upload into nicEdit

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

megan
01-15-2013 @ 10:12 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

Hello Smile

I am wanting to integrate nicEdit http://nicedit.com/ into an application

and it is really easy except that I also want to be able to make the upload image button functional on a cf server (in my case Railo 4)

to do that I had to point to the file I wanted to use
e.g. uploadURI : 'http://path/to/upload.cfm'

that is OK

the code inside the upload.cfm uploads the image to the desired place and creates a JSON representation of resulting data.

e.g. {"error":"","width":"100","done":"1","msg":"","url":"\/images\/myimage.jpg"}

Here's the code I have been playing with so far:

<cfset r = structNew()>
<cfset r['msg'] = "">
<cfset r['error'] = "">
<cfset r['done'] = "">
<cfset r['width'] = "">
<cfset r['url'] = "">

<cfset myuploadpath = "#GetDirectoryFromPath(
   GetCurrentTemplatePath()
    ).ReplaceFirst(
    "([^\\\/]+[\\\/]){1}$", ""
    )#">

<cfif isdefined("form.FIELDNAMES")>
      <cffile action = "upload" destination = "#myuploadpath#\images\" accept="image/*" nameconflict="makeunique">
<cfset r['done'] = "1">
<cfset r['width'] = "100">
<cfset r['url'] = "/images/#file.serverFile#">
<cfelse>
    <cfset r["error"] = "No file was uploaded.">
</cfif>
<cfoutput>#serializeJSON(r)#</cfoutput>


url, width, & done are the same as returned by the PHP version of an upload script at: http://nicedit.com/svn/nicedit/trunk/nicUpload/php/nicUpload.php

but for whatever reason, I cannot get the returned link to the image to be inserted into the nicEdit textArea the same as when using the default imageshack upload and I just do not know hardly anything about JSON (or PHP) in order to get this last step to fall into place

has anyone integrated a coldfusion upload into nicEdit? or do you have any suggestions for how I might proceed from here? I am so close but so far Frown

thanks for any help, Megan



-------------------------------------------------------
"The chief cause of failure & unhappiness is trading what you want most for what you want now." ~Zig Ziglar

megan
01-16-2013 @ 11:10 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

just to add to my earlier post - I realized I forgot to surround my JSON output with script tags

<InvalidTag  ><cfoutput>#serializeJSON(r)#</cfoutput>< /script >

and now I get the alert "Failed to upload image" from the nicEdit.js however the image IS uploaded

before I was just not getting anything so I consider this progress LOL

-------------------------------------------------------
"The chief cause of failure & unhappiness is trading what you want most for what you want now." ~Zig Ziglar

This message was edited by megan on 1-16-13 @ 11:12 AM

megan
01-16-2013 @ 11:50 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

Yippee - I got it to work - the JSON result format it was looking for was like this

<cfoutput>{"upload": { "links": {"original": "#r['url']#"}, "image": {"width": "#r['width']#" } }}</cfoutput>


the serializeJSON() function wasn't quite right and the php didn't indicate the right format I needed for the output

So SO Happy!! :D



-------------------------------------------------------
"The chief cause of failure & unhappiness is trading what you want most for what you want now." ~Zig Ziglar


Website Designed and Developed by Pablo Varando.