2009/08/29

Upload progress for Firefox 3.5

The new release of CKFinder 1.4 is due mainly to cover the integration with CKEditor 3, but it includes other little details, and I'm gonna talk about one of the here: the upload graph for Firefox 3.5

Upload graph

 

Firefox 3.5 might look boring for the users, it doesn't bring any special change to the interface or to the general options, but under the hood there are lot of changes for developers. Old bugs fixed, polishing, new features...  And among those new features there is something special for us: the ability to read the files picked with an <input type="file"> from javascript. Previously the only option was to read the filename and then submit the form to the server, without any ability to know how long it's taking.

A little history

In order to provide a progress bar you had to use some special coding at the server, so it could provide a progress info and poll that periodically. In some context it's far easier than in others, some require proprietary components, some require just a little script, but it's not easy to get it ready for every environment.

Then the Flash uploaders appeared. Macromedia did add a nice API to flash that allowed to easily pick several files from the user computer (of course, it's the user the one that selects the files) and then upload that data to the server, with event notification so now you can find several (lots?) of libraries to do that. One example is SWFUpload. But as far as I know, all of them have a problem due to the flash plugin itself: in non-IE browsers it fails to send back to the server the proper cookies, so it ruins the ability to keep authentication in the upload process. The trick then it's to send the data for the authentication cookie along the request and then recreate the session at the server with that info, I know that the code to do that in PHP and Asp.Net it's available and you can easily add that, but I've never seen such workarounds working for Asp (I don't know about CF). And even in Asp.Net you might need to alter files (global.asax) that you can't touch "to show a progress bar".

So as you can't see there is no easy solution "that works for everyone", but in the future that can be different.

The present

Starting with Firefox 3.5 you can use a new (non-standarized) API of the XmlHttpRequest: sendAsBinary. This post at hacks.mozilla.org  does explain it much better that I would be able to do in a lifetime.

So I went ahead and coded it for CKFinder.

  • Pros:
    • No changes required at the server,
    • It's based on feature detection, so if any other browser adds these APIs it will automatically work.
  • Cons:
    • Only Firefox 3.5,
    • We don't know how well it will perform with big files (1).

1: The Firefox API is based on reading the full contents of a file as a string and then sending it with a XHR, so if you pick a 1Mb file it means reading 1Mb of data, that looks easy. On the other side, if you are storing a 500Mb movie, then Firefox will go ahead and use in a moment 500Mb of additional memory. Wow, looks scary so we capped the feature so it's only triggered if the file is smaller than 20Mb.

The way that it's coded means that this is transparent to the user, he doesn't have to do anything and it will work. The form is just the same, the only change is the way that the data is sent to the server.

Other options

At the same time I evaluated the ability provided by Webkit that allowed to pass a file object to the XHR.Send() method, but it has some important drawbacks:

  • It's not possible to do feature detection on the ability, so it would need to be hardcoded using UserAgent strings. That's not nice
  • The file is sent to the server without any of the POST boundaries to wrap the data. That means that your standard code at the server won't work, you need to write special code to send the file name (easy) and then process the boundless data at the server (not so easy). In Firefox we have to add those boundaries, but the point is: It's possible to add them, so the server doesn't notice any difference between a standard form-post and this xhr.sendAsBinary()

There are lots of talk about this kind of features for inclusion in the new versions of XHR and related APIs, so I think that it's important to start testing what's available and provide feedback about what works and what fails.

I also tested the ability that Opera and Webkit offers to select multiple files with the <input type="file"> widget, and although it worked for Webkit, Opera did send the data using a set of headers that caused Asp.Net to consider it an attack, and crashed the AspUpload ActiveX from Persits (I didn't test it further as it was a dead road).

So in the future the ability to send multiple files with webkit might be added, also we will evaluate further the option to use a flash uploader so IE users get the option to both select multiple files and get a progress status, the important part is that the adjustments at the server side should remain within the CKFinder code, when you start requesting changes to global files then the problems start

Little bugs

Nevertheless, I don't think that the Firefox implementation is bug free.

The first problem is that the progress events are fired only when the server "consumes" the data. I mean: if you look carefully or put a sleep() at the server you will notice that the upload seems to stall at the end, although the data has been sent to the server, the browser doesn't notify that, it waits there, and looks strange.

As I said, reading the full file in memory doesn't look nice, it should be possible to request sending a file and the browser would read it just like it does with a normal form POST, it can read it little by little as it needs and with minimum overhead. In that situation we wouldn't need to restrict the maximum size, and this is important because getting progress info is more interesting when the file grows bigger.

If you notice any problem with this feature, please report it so we can look at it and fix it ASAP.

2009/08/27

CKEditor released

After a long time, finally the first stable version of CKEditor 3.0 has been released.

There are still some important features that are missing in order to do a smooth upgrade fro FCKeditor 2.x, but nonetheless this release is very important to really show what's coming with this new version.

I might add some follow up posts with small snippets of code about how to do some basic things with this version, trying to cover some areas that for the moment are lacking proper documentation.

These are the current articles:

  1. Using CKEditor, prerequisites.
  2. Creating an instance of CKEditor
  3. Delayed loading of CKEditor
  4. Creating CKEditor instances with Javascript

 

2009/08/08

Installing PHP in IIS 6 (windows 2003)

Some time ago I tried to install PHP in a test machine with Windows 2003 and IIS, so I could do some tests more easily. At that time I failed to get it working. The theory is simple, I found several tutorials explaining how to do it, but I wasn't able to get nothing but a "404 page not found" whenever I requested a .php page in that server.

Today I decided to try again. Quite a lot of things have changed in this time.

PHP has setup a separate site to handle installing PHP in Windows. Unfortunately the site is not as friendly as it seems that they are planning, but at least it's clear that they acknowledge the fact that there's a need for help installing PHP in windows. Besides the downloads it seems that there's little more in that site at the moment, but that download page is a little daunting:

Reading the sidebar you can see that you need to get the VC9 versions to install it in IIS, and the VC6 are meant to be used with the Apache server. But:
Thread safe or Not Thread safe?
Zip, Installer or Debug Pack?

Wouldn't it be better to move that Debug pack to somewhere else?

I'll skip some steps, and I would like you to introduce you this page that explains how to configure FastCGI and PHP in IIS.

You could have done the two first steps like I did, I downloaded the installer for PHP-non threaded-vc9 and when I tried to run it and configure for "IIS FastCGI" it warned to first download and install the FastCGI extension.

But you won't get the explanation about how to configure the FastCGI extension, so keep reading that page. I tried to do the automatic configuration using the script, but I got an error, so I don't know what's wrong. I tried to verify then all the steps according to he manual configuration and it seemed to be OK. But I got again a "404 page not found" trying to load any php page.

The next step was removing all of it and try with this automated installer for PHP in IIS . Yes, now Microsoft is hosting a whole site devoted to support for PHP in IIS, so this looks like a first stop when you try to get it working or troubleshoot something related to IIS and PHP. Wow.

After installing that "Web plataform installer" it took care of the rest by itself, each product was downloaded and installed, and I guess that it might have done that "configure FastCGI" in the bundle.

But again it didn't work!!!

The difference for me was that this time I knew that I was using the correct files, it's a tested installer, so I can't blame it on me due to having picked the wrong file in the PHP downloads (in this case I've noticed that they are using PHP 5.2.10 instead of the latest one PHP 5.3 that I picked).

So I tried to look more carefuly at it and then I noticed that under the "Default web site" properties it doesn't have assigned the .php script mapping. It was done correctly at the "Web sites" (parent folder), but not on the site itself. For some reason that setting didn't propagate to the child nodes, so I "edited" it and pressed OK, and it asked whether to update the value in the child sites. I said YES, and Now PHP Works!!!

As a summary:

The problem that I had was that the setting was correct for the "Web sites" node, but the real website node didn't get that setting applied, I guess that I might have messed previously (as I said this is a test machine) and those automatic scripts didn't try to update it.

 

 

2009/08/06

SWFObject plugin Update

Almost two months ago the fine folks at SWFObject did release the 2.2 version, so finally I've modified the FCKeditor plugin to make it use that version by default.

What does it means to you?

-If you don't use my plugin, not too much. Maybe you can take a look at it anyway if you are a FCKeditor user and don't like embeds.

-If you use the plugin, but are using a version of SWFObject hosted in your server, then you don't need to upgrade my plugin. Anyway, you might want to upgrade your copy of SWFObject, and if you place it with a different filename, then the upgrade of my plugin might be useful or you might end up including in the pages a link to the old library and another to the new one. Sorry, I didn't thought about it.

-If you are using the plugin and are relying on the externally hosted library, then it would be good to upgrade the plugin. The caveat is that you need to open and save again any page with a reference to the plugin to get it updated (unless your CMS has some option to do a search&replace in all the content). The good part is that even if you don't touch the existing content, the new files will use the new version.

Enjoy it

2009/08/02

Imgmap plugin update

Adam has been working on the imgmap code, and recently has released a new version to improve compatibility as well as fix some issues.

So finally I've upgraded the demo and the download link. If I ever forget again, just remember that the imgmap project is hosted at Google code.

I'll try to review these days all the mails that I have in the queue.

Edit

Now the CKEditor version of this imagemap plugin is available.

2009/07/22

Even Microsoft knows it

Just today I was a little surprised to read the System requirements for SharePoint Server 2010.

Two quotes:

To ensure the best possible experience across multiple browsers we’re focusing our SharePoint 2010 engineering efforts on targeting standards based browsers (XHTML 1.0 compliant) including Internet Explorer 7, Internet Explorer 8 and Firefox 3.x. running on Windows Operating Systems.  In addition we’re planning on an increased level of compatibility with Firefox 3.x and Safari 3.x on non-Windows Operating Systems.  Due to this focus Internet Explorer 6 will not be a supported browser for SharePoint Server 2010.

And

Q: What about Internet Explorer 6 and SharePoint 2010 publishing sites?
A: The Web Content Management features built into SharePoint 2010 will provide a deep level of control over the markup and styling of the reader experience.  These features will enable customers to design pages that are compatible with additional browsers for viewing content, including Internet Explorer 6.  A standards based browser such as Internet Explorer 7, Internet Explorer 8 or Firefox 3.x will be required to author content.

Yes, you are reading correctly.

Even Microsoft aknowledges that IE6 is a PITA, so you'll need something newer in order to author content there.

Little by little the web is moving forward, as more of these announcements popup everywhere people will finally realize that IE6 is a dead end, and that they must upgrade their browser if they want to use the new tools.

The reasoning should be easy:
Do you want to use the new tools? -> Use a new browser.
Do you want to keep using your old browser? -> You'll have to keep using tools and pages developed some years ago. Good luck with that!

Don't be afraid, IE8 doesn't require to install any WGA validation on your computer, it won't eat your children. Yes, it has bugs, but as the web moves to the future, the new webs are tested with the new browsers, and little by little IE6 fails into oblivion, so you'll see that more and more pages break in your old browser.

Stand up and say No to IE6! ;-)

2009/06/01

Google Maps v3

Just last week Google announced the third version of the Google Maps API.

It's a full rewrite, so for the moment it can't be used to replace the current maps in most of the sites (features like polylines and polygons are missing at the moment), but it can be tested and I might start porting the current plugin for FCKeditor to use the new API.

Why should I care about it if it isn't ready?

One of the first claims that you see is the compatibility with mobile browsers, that's nice. Improved speed is also welcome. Modularization means that less code is loaded and everything will work better, but....

NO KEYS REQUIRED!!!

(Sorry for the caps)

So when the new version of the plugin is released, you'll be able to use it in any site without worrying about getting and storing those stupid keys. If you have a site that it's served under different names it will work without any extra magic. OK, one problem might remain: the static maps do still require the key, but if it isn't available the rest of the functionality should work.

Things might go like this:
A version 2.3 for use in FCKeditor 2.x with the Maps Api 3
A version 3.0 for use in CKeditor 3.x with the Maps Api 3. This one will be easy to remember :-)

Of course, that 3.0 version might take a while, the v3 maps must get back enough of the functionality from the current version so it can be used without problems, and CKEditor v3 must be released and then I have to rewrite all the code so it can work with the new CKEditor API.

As you can imagine, rewriting all the code is not a pleasant task, and due to the work with new versions some unexpected bugs might arise that needs to be fixed at the other side.