Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using FileUploader and a view model to post
Message
 
 
À
28/02/2017 05:27:49
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01648596
Message ID:
01648627
Vues:
25
>Multipart form data can contain a mix of files and (for example) json objects. But I haven't used the MVC FileUpoader and don't know whether you can add additional parts on the client side before posting.
>
>In any case I don't see how you can create a valid FileUploadResult in javascript since it contains a HttpPostedFile instance and one of it's properties is a .NET stream.......

Hi Viv,

We're using Angular directive that incorporates the file uploader. The problem is that my page doesn't have direct access to the uploader itself, it has access to events that are executed after the upload happens.

So, I have the following problem. I have files from the uploader saved in the array and I have my model data (the model has a list of guests in addition to some plain properties).

My first question - how exactly can I send that list of files along with the model's data to my API code?

Right now my Save method in controller.js looks like this:
$scope.send = function (eMessage) {
                $scope.disableAction = true;
                if (eMessage.formType === 3) {
                    toastr.info(resourceFactory.getResource("Messages", "sendingEMail"));
                    //if (eMessage.attachments.length > 0)
                    //{
                    //    $.each(eMessage.attachments, function (index, fileInfo) {
                            
                    //        var reader = new FileReader();

                    //        reader.onload = function (e) {
                    //            var arrayBuffer = reader.result;
                    //            fileInfo.content = arrayBuffer;
                    //        }

                    //        reader.readAsArrayBuffer(fileInfo.content);
                    //    });
                    //}
                }
                else
                    toastr.info(resourceFactory.getResource("Messages", "sendingEMessage"));

                service.sendMessage(eMessage).then(function (data) {

                    var alertMessage = resourceFactory.getResource('Messages', 'sendingProcessCompleted');
                    toastr.clear();
                    toastr.success(alertMessage);

                    $scope.disableAction = false;
                    showSearchResults();
                });
            };
And my API C# function looks like this
 [Route("")]
        [HttpPost]
        public IHttpActionResult SendMessage(EditMessageViewModel messageViewModel)
and the service.js method looks like
this.sendMessage = function (message) {
            $log.debug("Sending message");
            return $http.post("api/EMessage", message);
        };
So, my question is - what should I change in order to send the files along with my model's data and then being able to read files binary content?

If that is too difficult, then alternative solution would be to somehow save my files with that binary content at the moment I upload them in the method I already shared - but then the question is - how exactly should I provide that temporary storage? Do you know how the repository can save information temporary? Some one was suggesting a static property of the repository, say, I can have a dictionary - does it sound to you a good approach or should I go ahead with the actual table to store these files? I can also, probably, save them files in some directory on the server and then retrieve them this way - but I don't like much that approach either.

So, what do you think and can suggest me?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform