I'm developing a Silverlight Business Application and want to implement a "multipart" upload, which splits a single file into parts with a size of 4096KB. To upload these parts from client to server, I'm using a WebClient (client side) and a generic handler (*.ashx, server side).
Strategy: With the first part a new instance of an Entity Framework class is created. This object has a field/property "binary" (in SQL it's a varbinary(MAX) and in Entity Framework it's a byte[]). I store the first part in the property "binary" and execute SaveChanges(). Then, the handler returns the ID (primary key) of this new object to the client.
The second request to the server contains, beside the second part of my file, the ID returned after the first request. On the server, I load the previously created object from the database and append the second part.
myobject.binary = myobject.binary.Concat(bytes).ToArray<byte>();
myobject is the previously created object, bytes the part I want to append to the binary property.
I repeat this "strategy" until the whole file is uploaded to the server. This works fine for files with a maximum size of ~78MB. For files with a size of ~83MB it works sporadic. Files with a size of ~140MB will abort with a OutOfMemory Exception at SaveChanges().
StackTrace
at System.Object.MemberwiseClone()
at System.Array.Clone()
at System.Data.Common.CommandTrees.DbConstantExpression..ctor(TypeUsage resultType, Object value)
at System.Data.Mapping.Update.Internal.UpdateCompiler.GenerateValueExpression(EdmProperty property, PropagatorResult value)
at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildSetClauses(DbExpressionBinding target, PropagatorResult row, PropagatorResult originalRow, TableChangeProcessor processor, Boolean insertMode, Dictionary`2& outputIdentifiers, DbExpression& returning, Boolean& rowMustBeTouched)
at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildUpdateCommand(PropagatorResult oldRow, PropagatorResult newRow, TableChangeProcessor processor)
at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
at System.Data.Mapping.Update.Internal.UpdateTranslator.<ProduceDynamicCommands>d__0.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Data.Mapping.Update.Internal.UpdateCommandOrderer..ctor(IEnumerable`1 commands, UpdateTranslator translator)
at System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at MyObjectContext.SaveChanges(SaveOptions options) in PathToMyEntityModel.cs:Line 83.
at System.Data.Objects.ObjectContext.SaveChanges()
at MultipartUpload.ProcessRequest(HttpContext context) in PathToGenericHandler.ashx.cs:Line 73.
Does anyone has an idea, what's wrong with my implementation? If you need more information or code snippets, please let me know it.
Kind regards, Chris