Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MuirisOG 382 posts 1284 karma points
    May 17, 2016 @ 17:03
    MuirisOG
    0

    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()
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 18, 2016 @ 06:25
    Jan Skovgaard
    0

    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

  • MuirisOG 382 posts 1284 karma points
    May 18, 2016 @ 09:33
    MuirisOG
    0

    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)
        //'...
    
  • MuirisOG 382 posts 1284 karma points
    May 18, 2016 @ 14:13
    MuirisOG
    0

    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

  • MuirisOG 382 posts 1284 karma points
    May 18, 2016 @ 16:40
    MuirisOG
    0

    ...and there's more. Chrome's developer tools show me this (no idea what it all means, tho).

    angular.min.js:106 POST http://umbraco.npt.gov.uk:743/umbraco/backoffice/UmbracoApi/Content/PostSave 500 (Internal Server Error)
    
    (anonymous function) @ angular.min.js:106
    
    o @ angular.min.js:102
    
    g @ angular.min.js:100
    
    i @ angular.min.js:79
    
    i @ angular.min.js:79
    
    (anonymous function) @ angular.min.js:80
    
    e.$eval @ angular.min.js:92
    
    e.$digest @ angular.min.js:90
    
    e.$apply @ angular.min.js:92
    
    (anonymous function) @ angular-mobile.js:269
    
    x.event.dispatch @ jquery.min.js:5
    
    y.handle @ jquery.min.js:5
    
  • MuirisOG 382 posts 1284 karma points
    May 19, 2016 @ 09:38
    MuirisOG
    100

    Ok... because I couldn't get this working, I've opted to use Media Picker instead, which seems to be working.

  • Matt Lawrence 5 posts 127 karma points
    Jul 29, 2016 @ 11:23
    Matt Lawrence
    2

    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.

  • Bo Jacobsen 593 posts 2389 karma points
    May 15, 2017 @ 10:03
    Bo Jacobsen
    0

    Had the same problem.

    You saved my day! :)

  • MuirisOG 382 posts 1284 karma points
    Jul 29, 2016 @ 12:05
    MuirisOG
    0

    Hi Matt

    many thanks for this.

    I've used an underscore in my Alias, so maybe that's where my code failed.

    Thanks,

    Muiris

Please Sign in or register to post replies

Write your reply to:

Draft