Working on a custom property editor for use on media documents. Editor contains a file upload. All is working fine on the client side, and on save a post is sent to /umbraco/backoffice/UmbracoApi/Media/PostSave exactly as when using the built in File media type. I am using fileManager.setFiles() to attach files to the form post.
Have checked the post using fiddler, can see that both json data for the form, and data for the file itself is in the post. In fact the only difference between the two posts is the contentTypeAlias of the form data and the property data.
Problem is that the api controller doesn't store the file that is being posted, but still reports back with a "Media saved without any errors" response.
Question is: Is there anything in the backend preventing recieving uploaded files and storing them, when the posting property editor is not a built in file upload property editor. I've based my custom editor on the code from the built in file upload editor.
Basically it's a file upload editor, without handling of images, and without the possibility of uploading a new file or removing already uploaded file. Controller looks like this:
function docStoreFileUploadController($scope, $element, $compile, imageHelper, fileManager) {
function initialize() {
$scope.originalValue = $scope.model.value;
$scope.persistedFiles = [];
$scope.files = [];
if ($scope.model.value.hasOwnProperty("selectedFiles")) {
var filenameArr = $scope.model.value.selectedFiles.split(",");
if (filenameArr.length > 0) {
$scope.persistedFiles.push({ name: filenameArr[0] });
}
}
}
initialize();
$scope.$on("filesSelected", function(event, args) {
$scope.$apply(function () {
fileManager.setFiles($scope.model.alias, args.files);
$scope.files = [];
var newVal = "";
for (var i = 0; i < args.files.length; i++) {
$scope.files.push({ alias: $scope.model.alias, file: args.files[i] });
newVal += args.files[i].name + ",";
}
$scope.model.value = { selectedFiles: newVal.trimEnd(",") };
});
});
}
angular.module("umbraco")
.controller('Docstore.FileuploadController', docStoreFileUploadController);
Have tried locating the code in the backend that handles the upload, no luck yet.
Yes, it is the responsibility of the property editor to save the file. So to answer your question:
Question is: Is there anything in the backend preventing recieving uploaded files and storing them, when the posting property editor is not a built in file upload property editor. I've based my custom editor on the code from the built in file upload editor.
YES
When a file is posted with json, we flag the file with the id of the property type, then when we pass the info to the property editor to retrieve the data to be stored in the db, we also pass it some 'additional data' which will include the file(s). It's up to the property editor to then deal with this data.
Copied the \Umbraco\Views\propertyeditors\fileupload\fileupload.html into my App_Plugins Folder for the UI and used the code parts from \Umbraco\Js\umbraco.controllers.js as the controller logic. Renamed the controller name and the function, so that there a no naming conflicts.
Everything seems to work on the client, but there isnt't any file uploaded. As I understand it is because my property editor's alias is My.UploadField and not Umbraco.UploadField that causes the logic not to do the upload, right?
Unfortunately the link above is not valid anymore. But actually I do not understand how to handle the upload by myself. Is there any tutorial, example or package that I can have a look on it?
Can anybody say something to this issue? What I simply want to achieve is creating a file upload editor that basically is the same as the built in, but has some slight differences in html markup.
Not sure if this is still a problem for you, I've managed to achieve what you are attempting by creating a DataEditor (in U8 - if you're on U7 it's a PropertyEditor) and using PropertyEditorAsset attributes to define my plugins assets.
I then delved into Umbraco 8 source code to part replicate how Umbraco handles the save etc against their FileUploadPropertyEditor and made sure I had a composer set up to register the property editor, and now have a working replica of the File Upload control.
I think you absolutely need your own property editor to make this work.
Custom file upload not storing file
Working on a custom property editor for use on media documents. Editor contains a file upload. All is working fine on the client side, and on save a post is sent to
/umbraco/backoffice/UmbracoApi/Media/PostSave
exactly as when using the built in File media type. I am usingfileManager.setFiles()
to attach files to the form post.Have checked the post using fiddler, can see that both json data for the form, and data for the file itself is in the post. In fact the only difference between the two posts is the contentTypeAlias of the form data and the property data.
Problem is that the api controller doesn't store the file that is being posted, but still reports back with a "Media saved without any errors" response.
Question is: Is there anything in the backend preventing recieving uploaded files and storing them, when the posting property editor is not a built in file upload property editor. I've based my custom editor on the code from the built in file upload editor.
Basically it's a file upload editor, without handling of images, and without the possibility of uploading a new file or removing already uploaded file. Controller looks like this:
Have tried locating the code in the backend that handles the upload, no luck yet.
Regards Jesper
Yes, it is the responsibility of the property editor to save the file. So to answer your question:
YES
When a file is posted with json, we flag the file with the id of the property type, then when we pass the info to the property editor to retrieve the data to be stored in the db, we also pass it some 'additional data' which will include the file(s). It's up to the property editor to then deal with this data.
Have a look here:
https://github.com/umbraco/Umbraco-CMS/blob/7.2.0/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs#L87
Hi,
Probably I ran into the same problem today.
Copied the
\Umbraco\Views\propertyeditors\fileupload\fileupload.html
into my App_Plugins Folder for the UI and used the code parts from\Umbraco\Js\umbraco.controllers.js
as the controller logic. Renamed the controller name and the function, so that there a no naming conflicts.Everything seems to work on the client, but there isnt't any file uploaded. As I understand it is because my property editor's alias is My.UploadField and not Umbraco.UploadField that causes the logic not to do the upload, right?
Unfortunately the link above is not valid anymore. But actually I do not understand how to handle the upload by myself. Is there any tutorial, example or package that I can have a look on it?
Kind regards, Stephan
Can anybody say something to this issue? What I simply want to achieve is creating a file upload editor that basically is the same as the built in, but has some slight differences in html markup.
Hi Stephan,
Not sure if this is still a problem for you, I've managed to achieve what you are attempting by creating a DataEditor (in U8 - if you're on U7 it's a PropertyEditor) and using PropertyEditorAsset attributes to define my plugins assets.
I then delved into Umbraco 8 source code to part replicate how Umbraco handles the save etc against their FileUploadPropertyEditor and made sure I had a composer set up to register the property editor, and now have a working replica of the File Upload control.
I think you absolutely need your own property editor to make this work.
Hope this helps, Keith.
is working on a reply...