0

Question

How do I solve this error message for an Easy Table that I've created in the Microsoft Azure Portal? This error occurs when I call MobileServiceClient.SyncContext.PushAsync:

OperationKind: Insert

Error Result: {
  "error": "request entity too large"
}

NuGet Packages

I am using the following NuGet Packages:

  • Microsoft.Azure.Mobile.Client v3.1.0
  • Microsoft.Azure.Mobile.Client.SQLiteStore v3.1.0

Code

    static bool _isInitialized;
    static MobileServiceClient _mobileService;

    public static async Task<IEnumerable<T>> GetItemsAsync<T>() where T : EntityData
    {
        await Initialize<T>();

        await SyncItemsAsync<T>();

        return await _mobileService.GetSyncTable<T>().ToEnumerableAsync();
    }

    public static async Task<T> GetItem<T>(string id) where T : EntityData
    {
        await Initialize<T>();

        await SyncItemsAsync<T>();

        return await _mobileService.GetSyncTable<T>().LookupAsync(id);
    }

    public static async Task AddItemAsync<T>(T item) where T : EntityData
    {
        await Initialize<T>();

        await _mobileService.GetSyncTable<T>().InsertAsync(item);
        await SyncItemsAsync<T>();
    }

    public static async Task UpdateItemAsync<T>(T item) where T : EntityData
    {
        await Initialize<T>();

        await _mobileService.GetSyncTable<T>().UpdateAsync(item);
        await SyncItemsAsync<T>();
    }

    public static async Task RemoveItemAsync<T>(T item) where T : EntityData
    {
        await Initialize<T>();

        await _mobileService.GetSyncTable<T>().DeleteAsync(item);
        await SyncItemsAsync<T>();
    }

    static async Task SyncItemsAsync<T>() where T : EntityData
    {
        await Initialize<T>();

        try
        {
            await _mobileService.SyncContext.PushAsync();
            await _mobileService.GetSyncTable<T>().PullAsync($"all{typeof(T).Name}", _mobileService.GetSyncTable<T>().CreateQuery());
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine($"Error during Sync occurred: {ex.Message}");
        }
    }

    async static Task Initialize<T>() where T : EntityData
    {
        if (_isInitialized)
            return;

        _mobileService = new MobileServiceClient(AzureConstants.AppServiceUrl);

        await ConfigureOnlineOfflineSync<T>();

        _isInitialized = true;
    }

    static async Task ConfigureOnlineOfflineSync<T>() where T : EntityData
    {
        var path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "azureSyncDatabase.db");
        var store = new MobileServiceSQLiteStore(path);
        store.DefineTable<T>();

        await _mobileService.SyncContext.InitializeAsync(store, new SyncHandler(_mobileService));
    }
Brandon Minnick
  • 11,396
  • 12
  • 55
  • 108
  • Does this help? http://stackoverflow.com/questions/36496043/azure-app-service-limits-body-size-to-64kb – Krumelur Feb 13 '17 at 19:13
  • Hey @Krumelur! This makes sense, but I'm not sure how to configure the backend, because I used Azure Easy Tables and I didn't manually create the API. – Brandon Minnick Feb 13 '17 at 19:27

1 Answers1

1

The Azure Mobile Apps backend is just a Node.js site that is pre-configured for you. You can use the App Service Editor to see the code behind the scenes.

Look at the Azure Mobile Apps Node.js HOWTO - it contains a section on making the size of the payload accepted bigger. Just implement the change in the App Service Editor and restart the service. Look for HOWTO: Handle Large File Uploads

If you are doing an insert, your data should not be that big though. Do not insert images or other larger items into a table - that's a bad practice.

Adrian Hall
  • 7,718
  • 1
  • 15
  • 26