AI OnAI Off
Hi Milos,
Had a quick look into this and if you want to change the destination of image uploads for all forms (which is what it sounds like) you could create a custom DataSubmissionService (EPiServer.Forms.Core.Internal) implementation.
Really simple example would be:
[ServiceConfiguration(typeof(DataSubmissionService), Lifecycle = ServiceInstanceScope.Singleton)]
public class CustomDataSubmissionService : DataSubmissionService
{
protected override FileSaveItem StorePostedFile(long postId, HttpPostedFileBase postedFile,
ContentReference folderLink)
{
var images = new [] { ".gif", ".jpg", ".png" };
var extension = Path.GetExtension(postedFile.FileName);
if (!images.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
// If the extension is not an image save to the default folder
return base.StorePostedFile(postId, postedFile, folderLink);
}
// Save images to the start page asset folder
var startPageAssetFolder = _contentAssetHelper.Service.GetOrCreateAssetFolder(ContentReference.StartPage);
return base.StorePostedFile(postId, postedFile, startPageAssetFolder.ContentLink);
}
}
and the IConfigurableModule to replace the default implementation:
[InitializableModule]
[ModuleDependency(typeof(Web.InitializationModule))]
public class CustomDataSubmissionServiceInitialization : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Services.AddSingleton<DataSubmissionService, CustomDataSubmissionService>();
}
public void Initialize(InitializationEngine context) {}
public void Uninitialize(InitializationEngine context) {}
}
That seems to be the easiest way to do it, unfortunately also touches a class in an internal namespace.
I see that when the default implementation creates the folder it also removes read access for the Every One role (see the GetOrCreateFolderForStoringFiles method), so you may want to consider that.
Happy New Year!
Is anyone aware of a way to take control of where file is saved when uploaded via File Upload element of Episerver Form?
Precisely, am looking for a way to set another destination (folder) where images land.