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

Specify File name on upload.

4 Answers 88 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Shaw
Top achievements
Rank 1
Shaw asked on 01 Apr 2012, 11:01 PM
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

4 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 04 Apr 2012, 01:32 PM
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.
0
Shaw
Top achievements
Rank 1
answered on 05 Apr 2012, 12:04 AM
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
0
Accepted
Kevin
Top achievements
Rank 2
answered on 05 Apr 2012, 01:03 PM
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.
0
Shaw
Top achievements
Rank 1
answered on 06 Apr 2012, 06:16 PM
Thanks Kevin!
Tags
Upload (Obsolete)
Asked by
Shaw
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Shaw
Top achievements
Rank 1
Share this question
or