locked
Unable to associate UploadOperation after App relaunch

    Question

  • i am trying my hands  on  with the  BTS sample app in C++ , which uploads a file using background transfer service .

    Once i select the files using file picker i am creating a seperate BackgroundUploader object 

    task<IVectorView<StorageFile^>^>(picker->PickMultipleFilesAsync()).then([this, uri]  (IVectorView<StorageFile^>^ files)
        {
            if (files->Size == 0)
            {
                rootPage->NotifyUser("Error: No file selected.", NotifyType::ErrorMessage);
                cancel_current_task();
            }       

            for (unsigned int i = 0; i < files->Size; i++)
            {
                BackgroundUploader^ uploader = ref new BackgroundUploader();
                //uploader->Method = "PUT";
                uploader->SetRequestHeader("Filename", files->GetAt(i)->Name);
                UploadOperation^ upload = uploader->CreateUpload(uri, files->GetAt(i));
                Log("Uploading " + files->GetAt(i)->Name + " to " + uri->AbsoluteUri + ", " + upload->Guid);
                HandleUploadAsync(upload, true);
            }

    Once the upload starts i am terminating my app. After the next relaunch i am trying to re-associate the uploadhandlers which is returning  progress attribute as "Error" after AtachAsync() call.

    void Scenario2::DiscoverActiveUploads()
    {
        task<IVectorView<UploadOperation^>^>(BackgroundUploader::GetCurrentUploadsAsync()).then([this] (IVectorView<UploadOperation^>^ uploads)
        {
            Log("Loading background downloads: " + uploads->Size);

            int uploadSize = uploads->Size;

            for (unsigned int i = 0; i < uploads->Size; i++)
            {
                 wstring fileName = uploads->GetAt(0)->SourceFile->Name->Data();
                UploadOperation^ upload = uploads->GetAt(i);

                wstring progress = upload->Progress.Status.ToString()->Data();

                Log("Discovered background upload: " + upload->Guid + ", Status: " + upload->Progress.Status.ToString());

                // Attach progress and completion handlers.
                HandleUploadAsync(upload, false);
            }
        }).then([this] (task<void> previousTask)
        {
            try
            {
                previousTask.get();
            }
            catch (Exception^ ex)
            {
                LogException("Discovery error", ex);
            }
        });


    Monday, May 27, 2013 9:56 AM

Answers

  • As per: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer.backgrounduploader.aspx

    After app termination, an app should enumerate all existing UploadOperation instances at next start-up using GetCurrentUploadsAsync. When a Windows Store app using Background Transfer  is terminated, incomplete uploads will persist in the background.  If the app is restarted after termination and these incomplete operations are not enumerated and re-introduced to the current session, they will go stale and continue to occupy device resources. Once enumerated, PUT upload operations are  automatically restarted, and POST upload operations are terminated.

    If you are using PUT, then the upload operations will be automatically restarted, POST requests will be terminated.

    The behavior for POST is expected, if you have a full repro, please upload your repro project, the server side component accepting the request and the files you are trying to upload to a SkyDrive location so that we can isolate the issue and help you further.


    @prashantphadke || Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, Windows Store & Phone Developer Solutions

    Monday, June 10, 2013 5:54 PM
    Moderator

All replies

  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to SkyDrive
    http://skydrive.live.com/

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 28, 2013 1:40 AM
  • I am trying my hands on  for Background transfer service  using the sample app in C++  (unable to post the link here  [ search in google for "background transfer service windows 8" the first list points to the sample App)

     )

    Once I  pick the file and initiate  a file upload, I had terminated the app before the server sends a  response.

    Even after  app  termination,  still the background upload succeeds, I am able to see http status code 200 in fiddler.

    But after restarting the app, I am unable to discover the active uploads.  

    The GetCurrentUploadsAsync() is giving us the vectorview of upload operations.

    Once I retrieve the UploadOperation^ object the status(upload->Progress.Status) is showing as “In Progress”.

    After this,  once I call AttachAsync() on the uploadOperation the status is changed to “Error” & upload->GetResponseInformation() is a nullptr.

    I would like to know if I am missing anything, I am expecting the status to be “Success” so that I can delete the uploaded file.

    I am sending the file using POST method and I am testing it on my localserver.

    I had also tried the same sample app in C# still I am facing the same issue.


    • Edited by vishy3 Tuesday, May 28, 2013 4:37 AM
    Tuesday, May 28, 2013 4:34 AM
  • Hello,

    Can you confirm if the below steps are sufficient to reproduce the issue?

    1.) Download the BackgroundUploader sample from here: http://code.msdn.microsoft.com/Background-Transfer-Sample-d7833f61

    2.) When the sample runs, click "Scenario 2" - File Upload

    3.) Choose "Start Multipart Upload" and then use the file picker to choose a few files

    4.) Once the files are selected, stop debugging the app.

    5.) Re-launch the app again and the error/exception should be seen.

    Can you also tell me the size of the individual files you are uploading and how many files you are uploading during this process?

    Thanks,

    Prashant.


    @prashantphadke || Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, Windows Store & Phone Developer Solutions

    Saturday, June 1, 2013 1:11 AM
    Moderator
  • As per: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer.backgrounduploader.aspx

    After app termination, an app should enumerate all existing UploadOperation instances at next start-up using GetCurrentUploadsAsync. When a Windows Store app using Background Transfer  is terminated, incomplete uploads will persist in the background.  If the app is restarted after termination and these incomplete operations are not enumerated and re-introduced to the current session, they will go stale and continue to occupy device resources. Once enumerated, PUT upload operations are  automatically restarted, and POST upload operations are terminated.

    If you are using PUT, then the upload operations will be automatically restarted, POST requests will be terminated.

    The behavior for POST is expected, if you have a full repro, please upload your repro project, the server side component accepting the request and the files you are trying to upload to a SkyDrive location so that we can isolate the issue and help you further.


    @prashantphadke || Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, Windows Store & Phone Developer Solutions

    Monday, June 10, 2013 5:54 PM
    Moderator
  • Once enumerated, PUT upload operations are  automatically restarted, and POST upload operations are terminated.


    Why??? What i have to do if I want to know result of uploading after restarting my application?

    I think it's really incorrect behaviour. While my applicatin isn't working uploading continues, if I start application then uploading are terminated.

    Friday, June 27, 2014 12:26 PM