Uploaded files being renamed to cryptic names

4 posts, 0 answers
  1. Craig Hauzie
    Craig Hauzie avatar
    14 posts
    Member since:
    Jan 2010

    Posted 22 Feb 2013 Link to this post

    I'm investigating migrating from the RadUpload control to the RadAsyncUpload tool and am seeing some weird behaviors.

    I have a RadAsyncUpload control on my web page and I've customized the TemporaryFolder in the Page_Load. I've also set up the OnFileUploaded method to do some custom work because we want to store a record of the file in our EFile database.

    When I do a postback ... the OnFileUploaded method fires and I can see that the e.File.GetName() method returns the correct name of my file but if I'm monitoring the TemporaryFolder -- the file name appears as names like "25j2deve.qc3" and "y20yq3q3.nz1". So then when my code goes to move the file from the TemporaryFolder to our own internal EFolder -- I keep getting the file does not exist because I'm trying to move it based on a file name from the e.File.GetName() method.

    I'm also confused by the documentation/tutorial because it uses a function to set the e.IsValid. The function is called CheckUploadedFileValidity().

    Where is that function? Is that something I need to write on my own? Is that built into a Telerik library somewhere?

    Do I need to be using the .SaveAs() method here like we did in the RadUpload tool? All I want to do is get a file into the temp folder and then I'll move it to the final location from there.

    e.IsValid = !CheckUploadedFileValidity();



  2. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 27 Feb 2013 Link to this post

    Hello Craig,

    This behavior is default for RadAsyncUpload- RadAsyncUpload relies on saving temporary files to work. When posted, files are saved to the designated temp folder (App_Data/RadUploadTemp by default) with unique names. Once a Postback occurs the RadAsyncUpload fires the OnFileUploaded event for each file. The target file is passed as part of the arguments to the event and can be set as either valid (default) or invalid. After the events fire, all files marked as valid are automatically saved to the TargetFolder if it’s set as it is mentioned in this documentation article

    So if you want to save the files to some directory I would recommend you just to set the Targetfolder accordingly and the file will be saved there.

    If you want to upload the file directly to your DateBase please refer to this on-line demo where similar scenario have been implemented with the help of custom handler. This article may be helpful as well for this scenario.

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Craig Hauzie
    Craig Hauzie avatar
    14 posts
    Member since:
    Jan 2010

    Posted 27 Feb 2013 Link to this post

    Thanks for the reply.

    But I do have some follow-up questions though.

    1. If I just set the TargetFolder accordingly ... what happens with duplicate file names? Specifically if two users upload files with the same name and they have the same target folder? It's my understanding that the last file uploaded will win and the first file will be overridden. Is that accurate?

    2. If #1 is true ... it seems like I need to go the custom handler route.

    3. If I didn't want to do the customer handler, could I just use the "e.File.SaveAs(destinationFileName)" method? In my code below ... I am going to determine if the file was valid or not, then call a utility function to get a unique file name based on the location in the EFolder where I want to save the file, then call e.File.SaveAs(....); I've got this solution working but just wasn't sure if there are known problems doing it this way that I'm not aware of.

    protected void radUpload_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        //some method to determine if file is/was valid
        e.IsValid = SomeMethod();
     
        //if valid, save to EFolder location
        if (e.IsValid)
        {
            string srcFileName = e.File.GetName();
            string destFileName = MiscUtils.GetUniqueFileName(srcFileName); //custom code
     
            e.File.SaveAs(destFileName);
        }
    }
  5. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 04 Mar 2013 Link to this post

    Hi Craig ,

     
    Thank you for getting back to us.

    1. Yes, the last uploaded file with the same name will "win" .
    2-3. Yes you could either Custom Handle or use the e.File.SaveAs in the FileUploaded event according to your logic. Your implementation seems correct.

    If you observe any other unusual issues or you have further questions I will be glad to assist you again.

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top