I've tried to create an Umbraco.UploadField in code for my own document type, but when I upload an image, I get an error message.
Any help would be appreciated:
The error is
An error occured
One or more errors occurred.
EXCEPTION DETAILS
System.AggregateException: One or more errors occurred.
STACKTRACE
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Umbraco.Web.WebApi.Binders.ContentItemBaseBinder`2.BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
at System.Web.Http.ModelBinding.ModelBinderParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
at System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
INNER EXCEPTION
System.AggregateException: One or more errors occurred.
at Umbraco.Web.WebApi.Binders.ContentItemBaseBinder`2.<>c__DisplayClass2.<BindModel>b__0(Task`1 x)
at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
INNER EXCEPTION
System.Web.Http.HttpResponseException: Processing of the HTTP request resulted in an exception.
Please see the HTTP response returned by the 'Response' property of this exception for details.
at Umbraco.Web.WebApi.Binders.ContentItemBaseBinder`2.<GetModelAsync>d__5.MoveNext()
Hi Jan
my code is in VB, and I think I've got all the relevant bits here. The other properties that I define work correctly, it's just this "upload" property that's failing.
I tried two methods (see the comments in the code below - note I have to use C#-style comments).
//'...the services I will use are...
Dim dts As IDataTypeService = ApplicationContext.Current.Services.DataTypeService
Dim cts As IContentTypeService = ApplicationContext.Current.Services.ContentTypeService
//'1. new Upload
Dim uploadNPTFileType As New DataTypeDefinition(-1, "Umbraco.UploadField")
uploadNPTFileType.Name = "NPT Page Image"
dts.Save(uploadNPTFileType)
//'...
//'2. create data types
//'Note: I also tried
//' Dim imgDataTypeDef As DataTypeDefinition = dts.GetDataTypeDefinitionById(-90)
//' but that didn't work either
Dim imgDataTypeDef As DataTypeDefinition = dts.GetDataTypeDefinitionByName("NPT Page Image")
...
//'create a doctype
Dim doctype As New ContentType(-1)
//'... followed by code to define my doctype
//'... then a tab for my property
doctype.AddPropertyGroup("System")
//'...
'create the image field
Dim imgPropType = New umbraco.Core.Models.PropertyType(imgDataTypeDef)
imgPropType.Name = "Page Image"
imgPropType.Alias = "p_image"
imgPropType.Description = ""
imgPropType.SortOrder = 0
doctype.AddPropertyType(imgPropType, "System")
//'...
cts.Save(doctype)
//'...
Umbraco.UploadField woes
I've tried to create an Umbraco.UploadField in code for my own document type, but when I upload an image, I get an error message. Any help would be appreciated:
The error is
Hi Muiris
What does your source code for this look like? I think that it's probably easier for people to help you out if you share it :)
/Jan
Hi Jan my code is in VB, and I think I've got all the relevant bits here. The other properties that I define work correctly, it's just this "upload" property that's failing.
I tried two methods (see the comments in the code below - note I have to use C#-style comments).
I can see a bunch of files in the /App_Data/TEMP/FileUploads folder, all with the correct file size for the images I'm uploading.
In fact, when I rename them, they are the files I've been uploading. They are all named "BodyPart_" followed by a random set of digits
...and there's more. Chrome's developer tools show me this (no idea what it all means, tho).
Ok... because I couldn't get this working, I've opted to use Media Picker instead, which seems to be working.
I just ran into what looks to be the same error (and Google brought me here).
In my case the error appears to happen for upload fields where the property alias contains an underscore (e.g. file_fr)
I've modified my document type so that the upload field property aliases don't contain underscores and they now work.
Had the same problem.
You saved my day! :)
Hi Matt
many thanks for this.
I've used an underscore in my Alias, so maybe that's where my code failed.
Thanks,
Muiris
is working on a reply...