Specify File name on upload.

Thread is closed for posting
5 posts, 1 answers
  1. Shaw
    Shaw avatar
    13 posts
    Member since:
    Sep 2011

    Posted 01 Apr 2012 Link to this post

    Hi - my users can upload an image of themselves as their profile picture. The image could have any random name. However, I'd like to save this file on the server with their UserID as the filename, not whatever they have it on their machine.

    I got this working by uploading and renaming but this seems sloppy and dangerous. What if they have the file named as someone else's UserID? 

    Any tips? Thank you!

    Shaw
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 04 Apr 2012 Link to this post

    Hello Shaw,

    If you are renaming the file in code, why does it matter what the user has the file saved as on their machine? If you don't have the TargetFolder set on the RadUpload control, the file gets uploaded to a temporary location that is completely isolated from your application.

    I don't see any problems with the way you're handling the file upload.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shaw
    Shaw avatar
    13 posts
    Member since:
    Sep 2011

    Posted 04 Apr 2012 Link to this post

    You're right, I think it would almost always be OK. I have the TargetFolder going to a temp directory to get it away from the actual files.

    However, if two users are uploading files with the same name couldn't they conflict with each other?

    Thanks,

    Shaw
  5. Answer
    Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 05 Apr 2012 Link to this post

    Hello Shaw,

    If you have the TargetFolder of the RadUpload set then I can see the issue occuring. As long as you have OverwriteExistingFiles set to false, you can use this approach to rename the file and prevent it from overwriting the other:

    http://www.telerik.com/help/aspnet-ajax/upload-server-side-fileexists.html

    I hope that helps.
  6. Shaw
    Shaw avatar
    13 posts
    Member since:
    Sep 2011

    Posted 06 Apr 2012 Link to this post

    Thanks Kevin!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017