Copied to clipboard

Flag this post as spam?

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


  • iNETZO 94 posts 414 karma points
    Jan 02, 2021 @ 14:30
    iNETZO
    0

    Interceptor for PostAddFile get empty file property

    Hi,

    I would like to intercept the upload of a file to the Media section. When the file is an video file, I would like to change the url so it is posting to a custom controller. I made the simple interceptor below:

    angular.module('umbraco.services').config([
        '$httpProvider',
        function ($httpProvider) {
    
            $httpProvider.interceptors.push(['$q', '$injector', 'notificationsService', function ($q, $injector, notificationsService) {
                return {
                    'request': function (request) {
    
                        if (request.url.indexOf("/umbraco/backoffice/UmbracoApi/Media/PostAddFile") === 0) {
    
                            if (request.file.name.endsWidth(".mp4")) {
                                request.url = "/umbraco/api/Video/PostAddFile";
                            }
    
    
                        }
    
                        return request || $q.when(request);
                    }
    
                };
            }]);
    
        }]);
    

    This fails because of the problem that the "file" property is added to the interception but is has a empty value. The other non-file properties have the posted values.

    This is the value config of the post request via $http: enter image description here

    This is the value of the config when intercepted enter image description here

    Is there someone who has experiences with intercepting an file-upload request?

    Best regard, iNETZO

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies