locked
Request entity too large (413). (Exception from HRESULT: 0x8019019D) in background file downloading

    Question

  • I am creating an app, in which I need to download some files ranging from 1 to 1000 according to users. I though to use background download API from WinRT. I implemented like given below. Now the problem is I am getting Request entity too large (413). (Exception from HRESULT: 0x8019019D) at random time. After that each file downloading task either throw that error or "Bad Request (400)". What could be cause of it? My requirement is to download files even if app goes to suspended state.

    Exception details:

    Request entity too large (413). (Exception from HRESULT: 0x8019019D)
    
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at XXXXX.YYYY.ZZZZZZ.<QueueDownloadFilesAsync>d__13f.MoveNext() in e:\Projects\xxx\yyy\aaa\qwerty.cs:line 1350

    private static List<Task> DownloadCompletionTasks = new List<Task>();
    
    public static async Task DownloadAllFilesAsync(string AccessToken)
    {
        foreach (var _file in _NewFiles)
        {
            var TargetFolder = await GetTargetFolderForNewFolderCreationAsync(_file.DepthLevel, _file.Path);
            if (TargetFolder != null)
            {
                DownloadCompletionTasks.Add(QueueDownloadFilesAsync(AccessToken, _file.DownloadUrl, TargetFolder, _file.FileName, CreationCollisionOption.ReplaceExisting));
            }
        }
    }
    
    await Task.WhenAll(DownloadCompletionTasks);
    
    public static async Task QueueDownloadFilesAsync(string AccessToken, string fileUrl, StorageFolder folder, string fileName, CreationCollisionOption CollisionOption)
    {
        try
        {
            if ((fileName.ToValidFileName() + folder.Path).Length < 256)
            {
                var file = await folder.CreateFileAsync(fileName.ToValidFileName(), CollisionOption);
                backgroundDownloader.SetRequestHeader("Authorization", "bearer" + " " + AccessToken);
                var DownloadOperation = backgroundDownloader.CreateDownload(new Uri(fileUrl), file);
    
                var progress = new Progress<DownloadOperation>(ProgressCallback);
                await DownloadOperation.StartAsync().AsTask(progress);    //---Exception occures here---
                ResponseInformation response = DownloadOperation.GetResponseInformation();
                if (response.StatusCode == 200)
                {
                    Debug.WriteLine("Download successfull.");
                }
                else
                {
                    Debug.WriteLine("Error occurred while downloading file. HTTP error code: " + response.StatusCode);
                }
            }
        }
    
        catch (Exception ex)
        {
            if (ex.ToString().Contains("entity too large"))
            {
                Debug.WriteLine("File name: " + fileName + "\nPath: " + folder.Path + "\n\n" + ex.ToString());
            }
            else
            {
                Debug.WriteLine(ex.ToString());
            }
        }
    }

    Wednesday, April 02, 2014 7:38 AM

Answers

  • I don't see any problem in your code offhand.  Like I said, if the requests are identical, and one request gets a valid response while the second request gets a 413 or 400, there's a problem on the server side.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 15, 2014 2:07 PM
    Moderator

All replies

  • You should consider using fiddler while testing this to see what the requests look like when they are sent to the server to see if any of them are sending large amounts of data.  Also, you may want to do a network trace on the server side to see if anything has changed between the client and the server.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, April 02, 2014 1:27 PM
    Moderator
  • Actually I am making an app which uses Google Drive as cloud storage. I tried to check the network traffic using fiddler. It shows only CONNECT request to download URL, when exception occurs, there's no different entry for that request which causes the exception. What to do now? If you  want the source code, I will give the app in stripped down version.
    Thursday, April 03, 2014 6:07 AM
  • You are going to have to talk to Google about what's going on with their server if they are throwing 413s with normal requests.  I don't think that reviewing the app is going to help in this case.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, April 03, 2014 2:00 PM
    Moderator
  • I think my code might using threading concept incorrectly. So I thought you check my code. What could be problem that it's throwing such exception?
    Tuesday, April 15, 2014 10:48 AM
  • I don't see any problem in your code offhand.  Like I said, if the requests are identical, and one request gets a valid response while the second request gets a 413 or 400, there's a problem on the server side.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 15, 2014 2:07 PM
    Moderator