This is a migrated thread and some comments may be shown as answers.

Additional parameters on upload

12 Answers 794 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edward
Top achievements
Rank 1
Edward asked on 20 Aug 2011, 12:34 AM
Hi there, I'm wondering if there is a way to pass additional parameters to the controller when uploading files. I would like to be able to upload a password protected document and a password all at the same time. Is this possible with the mvc upload control?

12 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 23 Aug 2011, 04:15 PM
Hi Edward,

Yes, this is possible. You can add metadata to files that are being uploaded asynchronously.

Alternatively, you can submit the upload as part of a form (synchronous upload) along with any other form fields.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Edward
Top achievements
Rank 1
answered on 23 Aug 2011, 08:10 PM
Thanks, it worked great. But the example for the client side metadata is incorrect. The controller method is using a description parameter instead of the fileDescription which is set in your javascript JSON object so it is coming out as null.

Your method is
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments, string description)

but should be
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments, string fileDescription)


Thanks.
0
T. Tsonev
Telerik team
answered on 24 Aug 2011, 08:50 AM
Hello Edward,

Fixed, thank you for the heads-up. Some Telerik points coming your way.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
ben
Top achievements
Rank 2
answered on 13 Sep 2011, 07:55 AM
Are you planning to implement something similar for file removal?
0
T. Tsonev
Telerik team
answered on 13 Sep 2011, 12:21 PM
Hello Ben,

You can use the OnRemove client-side event to send custom data in a similar way.

Kind regards,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ben
Top achievements
Rank 2
answered on 13 Sep 2011, 12:52 PM
Hi,

I have set up the onRemove client handler and attempted to use it to add metadata to the post in the same way as adding metadata to and upload.  When a client uploads an a file asyncronously it is added to a database, I would like the remove command to remove it from the database also, but need to identify the client that sent the request as well as the filenames being removed.

eg's
function onUpload(e) {
    e.data = { 'clientId': clientId };
}

function onRemove(e) {
    e.data = { 'clientId': clientId };
}
The onRemove function is called, but the post for remove does not include any form data or query string for any of the e.data. Can I somehow use the onRemove handler to add my own custom metadata?  Also what is the callback parameter that is added to the querystring? 

Thanks,
0
T. Tsonev
Telerik team
answered on 14 Sep 2011, 09:41 AM
Hello Ben,

This is a known issue that has been fixed. The fix is available in the Service Pack that will be released later today.

Kind regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ravi
Top achievements
Rank 1
answered on 04 Apr 2012, 03:59 PM
Hello,

We are using 2012.1.214 version and i am having the same problem with upload button. Like i am trying to upload which multiple is false and for the second upload it is calling Remove server method with params null. I want to send the filename to that method but i can't.

My code snippet is:

@(Html.Telerik().Upload()
                               .Name("attachments")
                               .Multiple(false)
                               .Async(async => async
                               .Save("SaveTempFile", "FileUpload")
                                .Remove("Remove", "FileUpload")
                               .AutoUpload(true))
                               .ClientEvents(events => events
                                       .OnLoad("OnLoad")
                                       .OnSuccess("OnSuccess")
                                       .OnRemove("OnRemove")
           ))

public JsonResult Remove(string[] fileNames, string file)
{
}

Client event OnRemove is calling when i click on Remove not for second upload. So how to pass fileName  param to server method.
I can be able to get the uploaded file name in fileNames array but i need to fill the other file param as well because while storing the file i am saving with guid as filename. 

I tried with  .Remove("Remove", "FileUpload", new { file = ViewBag.FileUniqueName }) as well but no use.
 
0
Karim
Top achievements
Rank 1
answered on 07 Aug 2012, 12:28 PM
Hi,
I had the same problem as Ben, the JS method (onUpload) is not called when running the code. (my telerik version is : Telerik_Extensions_for_ASPNET_MVC_2012_1_214_Commercial)
The  issue has not been fixed
 yet ?
0
OnyLee
Top achievements
Rank 1
answered on 07 Sep 2012, 01:11 PM
Hello,
Delete the file in the directory by sorting the files by date of creation

public ActionResult Remove(string[] fileNames)
        {
            // The parameter of the Remove action must be called "fileNames"
            foreach (var fullName in fileNames)
            {
                var fileName = Path.GetFileName(fullName);
                string uploadFolder = AppDomain.CurrentDomain.BaseDirectory + "UploadCommunity\\";
                DirectoryInfo directInfo = new DirectoryInfo(uploadFolder); //read directory to enumerate files
                FileInfo[] filelist = directInfo.GetFiles();
                var fileList = from n in filelist select new { FileName = n.FullName, CreationDate = n.CreationTime }; //get list of files by creationtime
                var latestFile = (from m in fileList orderby m.CreationDate descending select m.FileName).First<string>(); //get the first file from the sorted list (descending order)
                FileInfo file = new FileInfo(latestFile);
                file.Delete();
            }
            // Return an empty string to signify success
            return Content("");
        }
0
Deepa
Top achievements
Rank 1
answered on 28 Dec 2012, 02:33 AM
Hello ,

I am using the 2012.3.114 version and still having a problem passing parameters to the server Remove action.

Here's the code snippet 

 @(Html.Kendo().Upload()
          .Name("files")
         .Async(a => a
                          .Save("Save", "Home")
                         .Remove("Remove", "Home")
                          .AutoUpload(true)
          )
        .Events(events => events
                               .Select("onSelect")
                                .Upload("onUpload")
                                .Remove("onRemove")
                                .Error("onError")
          )
         )

   var onUpload = function(e) {
       e.data = { 'Id': $("#Id").val()};
    };
   
   var onRemove = function(e) {
        e.data = { 'Id': $("#Id").val()};
        };


In the controller the Remove always shows null for the passed in params. 
The same code for Upload works.

Please help.
0
Florin
Top achievements
Rank 1
answered on 19 Mar 2013, 10:07 AM
Can multiple parameters be used with only one upload control?  I need to send on Save, param for description but also a few more params like Notes,Category...(this will link a small form values  to one save, the upload save)
Tags
Upload
Asked by
Edward
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Edward
Top achievements
Rank 1
ben
Top achievements
Rank 2
Ravi
Top achievements
Rank 1
Karim
Top achievements
Rank 1
OnyLee
Top achievements
Rank 1
Deepa
Top achievements
Rank 1
Florin
Top achievements
Rank 1
Share this question
or