NetTalk Central

NetTalk Web Server => Web Server - Share Knowledge => Topic started by: MyBrainIsFull on February 21, 2015, 05:10:36 AM

Title: Redactor uploads images - chops the end of the filename - share knowledge
Post by: MyBrainIsFull on February 21, 2015, 05:10:36 AM
Hi, this is a hole I fell into and Bruce pulled me out of - for changing the folder they  are save into.

IF you use redactor
and drag and drop IMAGES,  you will know that they are IMMEDIATELY uploaded

and you can use the WebHandler in
     p_web.SaveFile PROCEDURE
to change the location of the upload,
from Web\  Uploads\Image123.Jpg  
to    Web\  Employee13\Image123.jpg

BUT
as I found out this was saved as Employee13\Image123.

NOTE
 - Uploads\Image123.Jpg       = 20 chrs
 - Employee13\Image123.jpg  = 23 chrs      THUS the last 3 chrs are cut off  !

Because the save is done by the line below the embed as
   ReturnValue = PARENT.SaveFile(p_name,p_filename)

What it does is to put the variable on the stack and call the parent.

BUT the stack is holding the SIZE of the incoming p_filename (20) and puts the 23 character Employee13\Image123.jpg on there cutting off the last 3 chrs

So no matter what you do the stack is going to truncate this string.

TO FIX (thanks Bruce)
Put a larger variable on the stack, so when its pushed onto the stack its bigger and does not truncate the string   IE  the call is passed to the parent ON THE STACK !

So I made a variable of 255 chrs and changed the SaveFile to this, using a var of 255 chrs.

-------------------------------------------------------
p_web.SaveFile PROCEDURE(STRING p_name,<STRING p_filename>)
ReturnValue          ANY
s255                    String(255)
  CODE
  
  !-----------[ INTERCEPT REDACTOR UPLOADING IMAGES ]-------------------!
         if self.PageName = 'redactorImageUpload'    
           s255 = clip(p_web.site.WebFolderPath) &p_filename      
       /// make changes to the path ///  ie s255 = blah/blah/blah/etc    
         end      
         ReturnValue = PARENT.SaveFile(p_name,s255)
         RETURN ReturnValue

  (the following part of the original code will never run )
      
  ! Parent Call
  ReturnValue = PARENT.SaveFile(p_name,p_filename)
  ! [Priority 7500]
  


Title: Re: Redactor uploads images - chops the end of the filename - share knowledge
Post by: Bruce on February 22, 2015, 11:59:26 PM
good tip Kevin.