Project

General

Profile

3.7 WFileDropWidget - how to cancel uploads

Added by Mark Petryk 9 months ago

Hi,

How can I simply cancel and then remove all dropped files;

In the code below (line 2535 and beyond), I want to throw away all the uploads and clear out the upload widget, and remove everything. How can I 'remove' the files from the uploads() vector? This code doesn't seem to work, and the uploaded files persist in the vector.

Looking at the source code, the 'remove()' function seems to trigger on the current index, and since the current index is zero at this point, nothing gets actually removed.

  2501  void
  2502  WEB::FolderTableView::
  2503  handleDrop( std::vector< Wt::WFileDropWidget::File *> _files )
  2504  {
  2505    std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
  2506      << " index:" << fileDropWidget()-> currentIndex()
  2507      << " size:"  << fileDropWidget()-> uploads().size()
  2508      << std::endl;
  2509  
  2510    /*
  2511    ** If the uploads are allowed, then do the upload
  2512    **  dialog thing.
  2513    **
  2514    */
  2515    if( m_pbUpload-> isEnabled() )
  2516    {
  2517      if( m_fileDropDialog )
  2518        delete m_fileDropDialog;
  2519  
  2520      /*
  2521      ** Open pop-up dialog to allow the user to see what is
  2522      **  uploading and its statuses and everything and all that.
  2523      **
  2524      */
  2525      m_fileDropDialog = new FileDropDialog( rootFolder(), currentFolder(), m_fileDropWidget );
  2526    }
  2527  
  2528    /*
  2529    ** Uploads are not allowed in this area, so just throw everything
  2530    **  away.
  2531    **
  2532    */
  2533    else
  2534    {
  2535      for( auto file : _files )
  2536      {
  2537        std::cout << __FILE__ << ":" << __LINE__ << " cancel:" << file-> clientFileName() << std::endl;
  2538  
  2539        fileDropWidget()-> cancelUpload ( file );
  2540      }
  2541  
  2542      std::cout << __FILE__ << ":" << __LINE__
  2543        << " all canceled:" << fileDropWidget()-> uploads().size()
  2544        << std::endl;
  2545  
  2546      for( auto file : _files )
  2547      {
  2548        std::cout << __FILE__ << ":" << __LINE__ << " remove:" << file-> clientFileName() << std::endl;
  2549  
  2550        fileDropWidget()-> remove       ( file );
  2551      }
  2552  
  2553  
  2554      /*
  2555      ** the uploads() should be empty, no?
  2556      **
  2557      */
  2558      std::cout << __FILE__ << ":" << __LINE__
  2559        << " all canceled:" << fileDropWidget()-> uploads().size()
  2560        << std::endl;
  2561  
  2562      Wt::WMessageBox::show("Drop File Upload", Wt::WString::tr( "fileDropUpload.wrongFolder" ), Wt::Ok );
  2563    }
  2564  


Replies (1)

RE: 3.7 WFileDropWidget - how to cancel uploads - Added by Matthias Van Ceulebroeck 5 months ago

Hello Mark,

I apologize for the very late response, it has been very busy lately.

It indeed is the case that remove() uses the current index as a cutoff, with the logic being that only uploaded files can be removed, and the current index should always correctly reflect the number of uploaded files.
So for some reason this doesn't appear to be the case.

Are you uploading files one by one, or uploading a couple at once? I'd like to be able to reproduce this problem.

Best,
Matthias

    (1-1/1)