Azure Easy Table:请求实体太大
Azure Easy Table: Request Entity Too Large
问题
如何解决我在 Microsoft Azure 门户中创建的 Easy Table 的错误消息?当我调用 MobileServiceClient.SyncContext.PushAsync
:
时出现此错误
OperationKind: Insert
Error Result: {
"error": "request entity too large"
}
NuGet 包
我正在使用以下 NuGet 包:
- Microsoft.Azure.Mobile.Client v3.1.0
- Microsoft.Azure.Mobile.Client.SQLiteStore v3.1.0
代码
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));
}
Azure 移动应用程序后端只是一个为您预配置的 Node.js 站点。您可以使用应用服务编辑器查看幕后代码。
查看 Azure Mobile Apps Node.js HOWTO - 它包含一个关于使接受的有效负载大小更大的部分。只需在应用服务编辑器中实施更改并重新启动服务即可。查找 HOWTO:处理大文件上传
如果您正在执行插入操作,那么您的数据应该不会那么大。不要将图像或其他较大的项目插入 table - 这是一种不好的做法。
问题
如何解决我在 Microsoft Azure 门户中创建的 Easy Table 的错误消息?当我调用 MobileServiceClient.SyncContext.PushAsync
:
OperationKind: Insert
Error Result: {
"error": "request entity too large"
}
NuGet 包
我正在使用以下 NuGet 包:
- Microsoft.Azure.Mobile.Client v3.1.0
- Microsoft.Azure.Mobile.Client.SQLiteStore v3.1.0
代码
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));
}
Azure 移动应用程序后端只是一个为您预配置的 Node.js 站点。您可以使用应用服务编辑器查看幕后代码。
查看 Azure Mobile Apps Node.js HOWTO - 它包含一个关于使接受的有效负载大小更大的部分。只需在应用服务编辑器中实施更改并重新启动服务即可。查找 HOWTO:处理大文件上传
如果您正在执行插入操作,那么您的数据应该不会那么大。不要将图像或其他较大的项目插入 table - 这是一种不好的做法。