Friday, June 25, 2010

Implementing file upload progress bar for the new PhilPapers

At first glance this seems like a trivial thing to do - you periodically observe how much of the file you've got and update the progress bar - so it did not look like much of work when I was assigned the task to replace the hodgepodge of technologies that provided that feature at the previous version of PhilPapers website. But a quick research of available Open Source solutions revealed that there aren't that many of them and none fitting our choice of technologies and in particular ones that don't use Flash - so bad lack I had to rewrite our own from scratch. This lack of ready-available libraries hints about the difficulties of that seemingly trivial task. I will describe here our solution - not because I think it is an optimal one - but to start a discussion of what could be such a solution.

First of all the common programming tools (like CGI.pm or Mason that we use here) assume that the page handler receives the whole request as input - and that whole request is not available until after the file is uploaded. So for example 'my $q = CGI.pm->new' will not finish until it is too late to measure the upload progress. The solution to that is to use another page to report the upload progress and call that page via Ajax from Javascript code updating the progress bar. This would work great - but the file is normally uploaded to a temporary file with a random name and the other script would not have any chance to guess it. We need to generate a new random file name in the form page and then pass that name to the form handler script so that it would save the data to that file, and in parallel to the Ajax scripts that would check the size of that file.


To save the data into a specified filename I used the CGI.pm callback feature:

my $q = CGI->new( \&hook, $fh, undef );
...
sub hook {
my ($filename, $buffer, $bytes_read, $fh) = @_;
print $fh substr($buffer, 0, $bytes_read);
$fh->flush();
}

It is described in the subsection called "Progress bars for file uploads and avoiding temp files" of the CGI.pm documentaion, but actually it is a great leap of thought to say that it supports progress bar implementation, you still cannot use it directly to get the progress bar from the CGI object on the form landing page, you still need the separate scripts measuring the progress. For my solution all I needed was to pass the target file name to the code saving the data, this could be easier than writing this callback above. And the callback is still not everything - I yet need a way to pass the generated filename from the form page to that script - and not via form parameters, remember they are not available at that stage. So how can that be done? Simple - as PATH_INFO - which is available in the %ENV hash even before the params are parsed by CGI.pm.

This is the skeleton of the solution - there are a few more details in the actual implementation - but the code will be published soon as Open Source - so I hope everyone will be able to look them up there.

50 comments:

  1. tiffany and co jewelry, http://www.tiffanyandco.in.net/
    prada handbags, http://www.pradahandbagsoutlet.co.uk/
    louis vuitton handbags, http://www.louisvuittonhandbag.us/
    tiffany jewellery, http://www.tiffanyjewelleryoutlets.co.uk/
    hermes belt, http://www.hermesbelts.us/
    ugg outlet, http://www.uggsoutlet.us.org/
    karen millen dresses, http://www.karenmillendressesoutlets.co.uk/
    replica watches, http://www.replicawatchesforsale.us.com/
    christian louboutin online, http://www.christianlouboutinonline.us.com/
    canada goose jackets, http://www.uggbootscheap.eu.com/
    gucci, http://www.borseguccioutlet.it/
    air jordan shoes, http://www.airjordanshoes.us.org/
    the north face outlet store, http://www.thenorthfaceoutletstores.org/
    louis vuitton, http://www.louisvuitton.in.net/
    ugg boots, http://www.uggbootsclearance.in.net/
    nobis outlet, http://www.wellensteyn.com.co/
    ray ban sunglasses, http://www.raybansunglassesonline.us.com/
    snow boots, http://www.wintercoats.us.com/
    lebron james shoes, http://www.lebronjames.us.com/
    beats by dr dre, http://www.beatsbydrdre-headphones.us.com/
    michael kors factory outlet, http://www.michaelkorsfactoryoutlets.in.net/
    cheap nhl jerseys, http://www.nhljerseys.us.com/
    montblanc pens, http://www.montblanc-pens.com.co/
    vans shoes, http://www.vans-shoes.cc/
    dansko outlet, http://www.dansko-shoes.us/
    2015109caihuali

    ReplyDelete
  2. شركة الطيب افضل شركة تنظيف كنب بالرياض نقوم بتنظيف الكنب بالرياص بافضل الطرق التي تجعلنا دائما فب المراتب الاولي في مجالات التنظيف عزيزي العميل عليك العلم بان الطيب من افضل شركات التنظيف بالرياض و بالمملكة العربية السعودية انك اذا كنت تريد شركة لتنظيف الكنب الخاص بك فنحن الطيب نقوم بتنظيف الكنب بافضل المواد او بافضل المنظفات التي تعد من اهم الاشياء التي تجعل المهمة ناجحة بنسبة كبيرة فنحن شركة الطيب شركة تنظيف كنب بالرياض نعمل علي تنظيف الكنب بافضل الطرق كما اننا نمتلك افضل طاقم من العمالة المدربة علي اعلي اساس متخيل شركة الطيب الاولي في خدمات التنظيف

    ReplyDelete
  3. Preceding consenting to a payday credit, it is imperative that you mindful of and consent to every one of the terms. Payday Loans

    ReplyDelete
  4. This can give you some data on which ones can be trusted and the ones you ought to avoid. Payday Loans San-diego

    ReplyDelete
  5. We are covering most of the cities and still giving you the best services within very short period with top notch satisfaction. We can trace us 24/7 and you are always welcome. check casher Edison

    ReplyDelete
  6. Commonly, here and now credits should be paid in two weeks. You may end up pushing when the due date due date arrives in light of the fact that something has come up and you can't completely reimburse the cash back on time. A considerable measure of moneylenders give you the alternative to subscribe to a 'move over' component, which more often than excludes charges.
    Cash Advance Chula-vista

    ReplyDelete
  7. On the off chance that you routinely utilize here and now credits to bring home the bacon, you may need to look for extra money related help or training. Payday credits can cost a ton of cash if utilized disgracefully. Payday Loans Corona

    ReplyDelete
  8. We actually love to oblige you the best things with 100% agreements and faster ever.
    check casher Holiday


    ReplyDelete
  9. Take every chance you get in life, because some things only happen once
    cara mengatasi darah haid menggumpal yang terus menerus

    ReplyDelete
  10. Book Andheri Escorts Services at low rates call on RiyaBatta for awesome Female Escorts in Mumbai. You can have fun with hot Model Mumbai Escort Girls 24/7.
    Andheri Escorts ||||| Call Girls in Andheri |||| Call Girls in Mumbai ||||| Andheri Escorts Service

    ReplyDelete
  11. Ghaziabad Escort service in Instructed, Proficient And, independent escorts attractive call girls in Ghaziabad. We are giving best escorts services ensured full fulfillment. Call me, 9873940964 Out Call both kind of Call Girls services in Ghaziabad Escorts

    Ghaziabad Escort
    modal call girls ghaziabad
    independent ghaziabad call girls
    house wife in ghaziabad


    ReplyDelete
  12. independceCnt escorts services and many others by lovely call girls in Ghaziabad associated with her are ready to provide erotic fun.call us 9873940964

    call girls ghaziabad
    female escorts ghaziabad
    independent ghaziabad escorts

    ReplyDelete

  13. preetkour Independent Escorts in jodhpur VIP Prominent Escort Service in jodhpur,You can make escort in jodhpur a slave for the night,Book her to make today around evening time more agreeable with sexual fun. call us 9711199012

    Jodhpur call girls
    Jodhpur college call girls
    Jodhpur escorts service

    ReplyDelete
  14. On the off chance that you adore the enthusiastic way of life and need to appreciate it, you require a correct accomplice to give a decent organization. Maintain a strategic distance from depression by meeting the sizzling female and play with her awe-inspiring figure

    Jodhpur call girls
    Jodhpur college call girls
    Jodhpur escorts service

    ReplyDelete
  15. Get Stunning noida Escorts For All at very affordable prices covering all noida at Urgently book call girls whatsapp/Call 9873777170

    Escorts in noida
    Escorts service in noida

    ReplyDelete
  16. lizaroy is a lovely Russian escort in Faridabad who is a combo of excellence with brains. She knows how to give great organization to courteous fellows and how to be shrewd in bed. I have an expansive arrangement of sexual administrations to give an excite in quaint little inn you my fan. Contact us on :- 9873940964 and get more information about us visit my site :-
    Faridabad Call Girls
    Faridabad college Call Girls
    Faridabad Russian Call Girls
    Escorts in Faridabad
    Faridabad Escorts

    ReplyDelete
  17. Welcome Gentlemen, my name is Nikita and here as an Indian Escort in Delhi. who gives requesting warm and awesome relationship for respectable men. They're enthusiastic to fulfill you and need you to have the best time. They'll fulfill every single one of your desires and dreams. I am so charming with hot body. I knows how to do both: awesome sex and a great deal of fun! For get more details visit our website :-
    Delhi escorts
    Delhi Independent escorts
    Delhi Call Girls
    Delhi College Call Girls
    Delhi Russian Call Girls

    ReplyDelete
  18. welcome to the universe of excellence . Meet our escorts young ladies meenakshiroy . She is only 24 years of age and is here legitimately to exhibit her ability in offering joy to the clients like you. The Noida escorts Independent like me are free and feel no commitment to meet every one of the requests of the clients. My magnificence and conduct make me the correct buddy for multi day among the Noida escorts .visit my site:-
    Noida escorts
    Noida call girls
    Noida independent escorts

    ReplyDelete
  19. One of the happiest days of your life, you will like to hang out with a girl with whom you will feel like your girlfriend and you will get exactly the same dates. This girl is completely lost in the society. Nobody can even guess. Whom are you roaming with this girl specializes in the skill of fulfilling you completely, visit our website for complete information and call us on :-9873940964

    Faridabad escorts

    ReplyDelete
  20. Hello friends My name is pooja Goel . I live in Faridabad. I am 23 years old. I am a girl of open thoughts. Would you like to spend my life with me in the evening? I will be happy to thank you for your work thoroughly. For this, you have to call our no. 9873940964 For more information visit our website:-
    Faridabad Call Girls
    Faridabad Russian Call Girls
    Escorts in Faridabad
    Housewife in Fraidabad

    ReplyDelete
  21. Hello friends My name is pooja Goel . I live in Faridabad. I am 23 years old. I am a girl of open thoughts. Would you like to spend my life with me in the evening? I will be happy to thank you for your work thoroughly. For this, you have to call our no. 9873940964 For more information visit our website:-
    Faridabad Call Girls
    Faridabad Russian Call Girls
    Escorts in Faridabad
    Housewife in Fraidabad


    ReplyDelete
  22. Tanya Malik is the most delightful escort in Ghaziabad at present. So don't miss the possibility of meeting this beauty. Her magnificence is apparent from her delectable lips and her dazzling figure. she adores doing bad-to-the-bone sex with youthful guys. for get more data get in touch with us on :- 9873940964 and visit my site :-
    Ghaziabad Call Girls
    Ghaziabad college Call Girls
    Ghaziabad Russian Call Girls
    Escorts in Ghaziabad

    ReplyDelete
  23. Are you looking for the hot call girls in Ghaziabad to accompany you for pleasure? Her curvy statistics is 32-26-32. She is 5’6” with a perfect body weight of 52 kilos. I am here to fulfill all your deepest desires and fetishes. for booking me contact us on : 9873940964 and visit my website :- http://sonianegi.in/
    Ghaziabad Call Girls
    Ghaziabad college Call Girls
    Ghaziabad Russian Call Girls
    Escorts in Ghaziabad

    ReplyDelete
  24. Call @ 0(987)3940964 Lajpat nagar Escorts provides college girls, Independent Escorts in Lajpat nagar such as supermodel Russian Call Girls in Lajpat nagar for fun in full night and day so book now Lajpat nagar escort service.

    connaught place escorts ####
    dwarka escorts ####
    indirapuram escorts ####

    ReplyDelete
  25. Mr.Ajay Shastri is a famous astrologer in Pune, the world's famous astrologer, Pune No. 1 astrologer in Pune, astrologer, best astrologer Pt by 100% Solutions. Contact Now Ajay Shastri Pune 7837827129.

    https://astrologerinpunee.wordpress.com/

    https://astrologerinpunee.tumblr.com/

    https://imgur.com/2fgUhLf

    https://astrologerinpunee.quora.com/

    https://twitter.com/astrologer45

    http://astrologerpune.blogspot.com

    ReplyDelete
  26. vaishali Escorts Gallery with lots of real vaishali Escorts profiles. Call on 9873940964 to hire amazing call girls in vaishali and vaishali Escorts Services.


    noida escorts $$$$$$$$
    saket escorts $$$$$$$$
    delhi escorts $$$$$$$$
    rohini escorts $$$$$$$$
    mahipalpur escorts $$$$$$$$

    ReplyDelete
  27. Hot sizzling Call Girls in Delhi available 24X7 @ 9999965857 for full satisfaction. You will get affordable, rewarding Escorts in Delhi Service, Hire Model Delhi Escorts.

    mahipalpur escorts %%%%%%%
    hyderabad escorts %%%%%%%
    raipur escorts %%%%%%%
    pitampura escorts %%%%%%%
    faridabad escorts %%%%%%%
    gurgaon escorts %%%%%%%
    noida escorts %%%%%%%

    ReplyDelete
  28. we are provide a better travel sevices to book our travel tour train tickets,air tickets,bus tickets: Railway Station ticket counter or through online train ticket booking with cheap rate price Call @ 9990756667.

    train ticket agents in delhi

    railway ticket agent in delhi

    tatkal railway ticket agent delhi

    online railway ticket booking

    ReplyDelete
  29. Mumbai Escorts |call @8652582954 Provides You Best Escorts Services



    borivali escorts %%%%%%
    chembur escorts %%%%%%
    churchgate escorts %%%%%%
    colaba escorts %%%%%%
    dadar escorts %%%%%%
    malad escorts %%%%%%

    ReplyDelete
  30. Hello guys | 9837940964 | are you looking for fresh and lovely Rozy Call Girls. Delhi Escorts Service | Contact Us Without any hesitation Book here Fresh Call girls who can fulfill your all burning desire. Plz Vzt our site http://shanvibhardwaj.in/gallery.html
    Delhi Escorts

    Delhi Call Girls

    Call Girls in Delhi

    Female Escorts Delhi

    Delhi Escorts Service

    Russian Call Girls Delhi

    Housewife Escorts Delhi

    ReplyDelete
  31. http://minakshikumari1.strikingly.com/ Hi Friends I Am ghaziabad call Girl. I am local girl From Ghaziabad | I Provide You Best And Cheap Ghaziabad Call Girls | I am Linked to an Escorts agency in Ghaziabad | These Escort Girls Spend Dazzling Moments With You. Contact Mo. 9899900591
    vaishali escorts

    gaur city escorts

    sahibabad escorts

    kaushambi escorts

    indirapuram escorts

    ahinsa khand escorts

    greater noida escorts

    crossings republik escorts

    raj nagar extension escorts

    ReplyDelete
  32. trusted and affordable Escort Service in Delhi. " http://sweetgirl.strikingly.com/ "dial 9711199171 to have the best n good looking Call Girls in Delhi. satisfy your every wild desire with our lovely, Rozy and pretty call girls. all these call girls are available in delhi or nearby delhi areas location 24 hours.

    Ashram Escorts

    New Friends Colony Escorts

    Okhla Escorts

    Mukherjee Nagar Escorts

    Jangpura Escorts

    Green Park Escorts

    Chattarpur Escorts

    Laxmi Nagar Escorts

    Nizamuddin Escorts

    ReplyDelete