Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Forms file upload error

Jay
Jay
Vote:
 

Whenever I try to upload a file on a form I get the following js error:

If I don't add a file then the form submits fine. This is on my local dev environment.

Using EpiServer CMS V11.9 and EPiserver Forms V4.14.1

#222213
Edited, Apr 30, 2020 11:26
Vote:
 

You can see if there is any request to server which return 500 error, looking to the message on that. It will be a hint to determine your proplem.

#222444
May 06, 2020 3:58
Jay
Vote:
 

I found the  problem with this.

When uploading am image the mediadata we have set up for images has a required property, as this isn't set it fails the validation.

To get round I used a custom DataSubmissionService which turns off the validation check for files by overriding the StorePostedFile and in the FileContentLink set SaveAction.SkipValidation

    [ServiceConfiguration(typeof(DataSubmissionService), Lifecycle = ServiceInstanceScope.Singleton)]
    public class CustomDataSubmissionService : DataSubmissionService
    {
        protected override FileSaveItem StorePostedFile(long postId, HttpPostedFileBase postedFile,
            ContentReference folderLink)
        {
            var fileName = postedFile.FileName;
            var fileSaveItem = new FileSaveItem {FileName = fileName, FileSize = (long) postedFile.ContentLength};
            var str1 = Path.GetFileNameWithoutExtension(fileName);
            if (!string.IsNullOrWhiteSpace(str1) && str1.Length > 50)
                str1 = str1.Substring(0, 50);
            var str2 = new Regex(
                $"[^{(object) ServiceLocator.Current.GetInstance<UrlSegmentOptions>().ValidCharacters}]{{1}}").Replace(Path.GetExtension(fileName), "-");
            try
            {
                var contentType = this._contentTypeRepository.Service.Load(this._contentMediaResolver.Service.GetFirstMatching(str2));
                var contentMedia = this._contentRepository.Service.GetDefault<IContentMedia>(folderLink, contentType.ID);
                var blob = this._blobFactory.Service.CreateBlob(contentMedia.BinaryDataContainer, Path.GetExtension(str2));
                DataSubmissionService._logger.Debug("Blob is created at \"{0}\".", (object)blob.ID);
                blob.Write(postedFile.InputStream);
                contentMedia.Name = $"{(object) str1}_{(object) postId}{(object) str2}";
                contentMedia.BinaryData = blob;
                fileSaveItem.FileContentLink = this._contentRepository.Service.Save((IContent)contentMedia, SaveAction.SkipValidation, AccessLevel.NoAccess);
                DataSubmissionService._logger.Debug("Content for file \"{0}\" is created.", (object)fileName);
                fileSaveItem.Success = true;
            }
            catch (Exception ex)
            {
                DataSubmissionService._logger.Error("Could not store the posted file.", ex);
                return (FileSaveItem)null;
            }
            return fileSaveItem;
        }
    }
#225475
Jul 17, 2020 7:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.