如何解决我在Microsoft Azure门户中创建的Easy Table的错误消息?当我拨打MobileServiceClient.SyncContext.PushAsync
时发生此错误:
OperationKind: Insert
Error Result: {
"error": "request entity too large"
}
我正在使用以下NuGet包:
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));
}
答案 0 :(得分:1)
Azure移动应用后端只是一个为您预先配置的Node.js站点。您可以使用App Service Editor查看幕后代码。
查看Azure Mobile Apps Node.js HOWTO - 它包含一个关于使有效负载大小更大的部分。只需在App Service Editor中实现更改并重新启动服务即可。寻找HOWTO:处理大型文件上传
如果您正在进行插入操作,那么您的数据应该不会那么大。不要将图像或其他较大的项目插入表格 - 这是一种不好的做法。