File Upload

122 views
Skip to first unread message

Mike Fellows

unread,
May 6, 2010, 4:30:10 PM5/6/10
to Cappuccino & Objective-J
Hi,

I've been trying to understand how to get a file(s) upload button
working. The following issue discusses file uploads:

http://cappuccino.lighthouseapp.com/projects/16499/tickets/121-need-for-a-cpopenpanel

It's a feature request from about a year and a half ago. In the
comments the following code snippet is referenced (I think):

http://gist.github.com/92846

I've been playing around with the code snippet and trying to get it to
work with the latest nightly build of Cappuccino. There are a few
minor syntax issues, but after fixing those I've run into a more
interesting problem. It seems that the _fileUploadElement.onmousedown
callback is not successfully passing the mouse down event through to
the Cappuccino layer so that the UploadButton object can then re-catch
the event and show the button being depressed (it is then supposed to
"disposes" of the event through a couple of event call backs). The
code is a little convoluted in this regard so perhaps I'm
misunderstanding.

The result of this problem is the button does not depress when you
click on it, and the button only responds with a file open dialog on
every second click. I'm running this on firefox 3.6.3, I've also
tried with firefox 3.5 with the same result.

Has anyone else been working with this code recently? Or is there a
more up to date example of a file upload button out there somewhere?

Regards,
Mike

--
You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
To post to this group, send email to objec...@googlegroups.com.
To unsubscribe from this group, send email to objectivej+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/objectivej?hl=en.

Chandler Kent

unread,
May 6, 2010, 9:22:39 PM5/6/10
to Cappuccino & Objective-J
We use that code for our project. We recently discovered it was broken
in the latest master due to this commit:

http://github.com/280north/cappuccino/commit/0e4d476d76dea59ce44d28486cd7698f819d072e

However, this commit is reverted in 0.8.1, so those frameworks work
fine.

On May 6, 4:30 pm, Mike Fellows <Mike.Fell...@shaw.ca> wrote:
> Hi,
>
> I've been trying to understand how to get a file(s) upload button
> working.  The following issue discusses file uploads:
>
> http://cappuccino.lighthouseapp.com/projects/16499/tickets/121-need-f...

Mike Fellows

unread,
May 7, 2010, 12:56:33 PM5/7/10
to Cappuccino & Objective-J

I've tested the code with 0.7.1, 0.8.1 and the latest nightly build
all with the same results - the Upload File button doesn't click down
when the button is clicked. Other than that everything works fine.
File uploads work, status and error reports work fine.

Perhaps I'm not using the FileUpload object properly? I've included
the test AppController.j below. FileUpload.j is the unaltered code
from gist except for adding ampersands to the three import statements
at the head of the file (i.e. @import instead of import). So what am
I doing wrong?

Mike


<AppController.j> ...

@import <Foundation/CPObject.j>
@import "FileUpload.j"


@implementation AppController : CPObject
{
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc]
initWithContentRect:CGRectMakeZero()

styleMask:CPBorderlessBridgeWindowMask];
var contentView = [theWindow contentView];

var fileUploadButton = [[UploadButton alloc]
initWithFrame:CGRectMake(10, 10, 100, 24)];
[fileUploadButton setTitle:"Upload File"];
[fileUploadButton setBordered:YES];
[fileUploadButton setURL:"http://localhost:2345/file_upload/"];
[fileUploadButton setDelegate:self];
[contentView addSubview:fileUploadButton];

[theWindow orderFront:self];
}

-(void) uploadButton:(UploadButton)button didChangeSelection:
(CPString)selection
{
console.log("Selection has been made: " + selection);

[button submit];
}

-(void) uploadButton:(UploadButton)button didFailWithError:
(CPString)anError
{
console.log("Upload failed with this error: " + anError);
}

-(void) uploadButton:(UploadButton)button didFinishUploadWithData:
(CPString)response
{
console.log("Upload finished with this response: " + response);

[button resetSelection];
}

-(void) uploadButtonDidBeginUpload:(UploadButton)button
{
console.log("Upload has begun with selection: " + [button
selection]);
}

@end



On May 6, 6:22 pm, Chandler Kent <ckents...@gmail.com> wrote:
> We use that code for our project. We recently discovered it was broken
> in the latest master due to this commit:
>
> http://github.com/280north/cappuccino/commit/0e4d476d76dea59ce44d2848...
>
> However, this commit is reverted in 0.8.1, so those frameworks work
> fine.

Mike Fellows

unread,
May 7, 2010, 2:24:04 PM5/7/10
to Cappuccino & Objective-J

> I've tested the code with 0.7.1, 0.8.1 and the latest nightly build
> all with the same results - the Upload File button doesn't click down
> when the button is clicked.  Other than that everything works fine.
> File uploads work, status and error reports work fine.

Sorry, minor correction. Chandler was right about the latest builds
causing a problem. Only every second click on the button works with
the latest nightly builds, not a problem with 0.7.1 or 0.8.1. Still
for all three cases the button doesn't appear to depress when
clicked. I've tested it on Chrome, Safari, and firefox 3.5 and 3.6.

Regards,
Mike

Randy Luecke

unread,
May 7, 2010, 2:43:27 PM5/7/10
to Cappuccino & Objective-J
If you click the top of the button it works…

I'm not really sure why it does that, and I believe Sofa fixed it, but
I haven't taken a look yet.

Mike Fellows

unread,
May 7, 2010, 3:03:31 PM5/7/10
to Cappuccino & Objective-J

On May 7, 11:43 am, Randy Luecke <rclconce...@gmail.com> wrote:
> If you click the top of the button it works…

Are you referring to the button not appearing to depress when you
click on it, or the problem with the latest nightly that required two
clicks to get it to respond?


I have found a workaround that gets the button to depress by following
notes in this thread:
http://groups.google.com/group/objectivej/browse_thread/thread/e02f83870a9230d1/482c9b19efe853be?lnk=gst&q=File+Upload#482c9b19efe853be

I modified FileUpload.j to include the following line below the [CPApp
sendEvent ...] in both _mouseDownCallback and _mouseUpCallback:
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];

The button now depresses and returns to normal when it is clicked and
released (there is a bit of a lag, but I can live with that). This
run loop fiddling was just a shot in the dark, is this a reasonable
thing to do to get this to work?


Regarding the problem with the latest build causing the button to only
respond on every second click, it seems to go away if the mouseDown
method is removed from FileUpload.j. Everything else seems to work.
I'm guessing the change that Chandler referred to that broke his code
in 0.8.0, was reverted in 0.8.1 and is now back in the development
releases, addresses the same issue that the mouseDown and
disposeOfEvent code was fixing in FileUpload.j? Can anyone confirm if
this is true?

Randy Luecke

unread,
May 7, 2010, 3:18:43 PM5/7/10
to Cappuccino & Objective-J
sorry, prior to the commit that broke it… :)

On May 7, 2:03 pm, Mike Fellows <Mike.Fell...@shaw.ca> wrote:
> On May 7, 11:43 am, Randy Luecke <rclconce...@gmail.com> wrote:
>
> > If you click the top of the button it works…
>
> Are you referring to the button not appearing to depress when you
> click on it, or the problem with the latest nightly that required two
> clicks to get it to respond?
>
> I have found a workaround that gets the button to depress by following
> notes in this thread:http://groups.google.com/group/objectivej/browse_thread/thread/e02f83...

Mike Fellows

unread,
May 19, 2010, 10:43:10 PM5/19/10
to Cappuccino & Objective-J
Just a bit of an update on File Upload. I've created a github
repository with a collection of changes to bring the File Upload code
up to date. It is located here:

http://github.com/MCF/FileUpload

Check the README and the wiki for the project for more details on how
to use the code. There are several branches available depending on
which set of features you want, and which version of Cappuccino you
will run against.

The current Master branch for the code also includes support for
multiple file upload provided by the new "multiple" attribute for
input elements available in html5. The feature only works in newer
browsers (Ffox 3.6, Chrome 4.1, Safari 4.0 - and of course not
available yet in any version of IE). Still the multiple file upload
will degrade back to single file if the underlying html/DOM stuff
doesn't support it.

Any questions/comments/criticisms welcome.

Regards,
Mike
Reply all
Reply to author
Forward
0 new messages