1

I'm using FileUpload to retrieve uploaded image, however, i want to detect the original file path from where user picked the photo from, before user submitted the entry.

This is to display image before user submits the entry, without uploading photo to the folder directory of server hosting at first.

Jeosiyy Chu
  • 67
  • 2
  • 15
  • You can't display the image before saving to the DB, that doesn't make sense... If a user picks an image you can still show them the image before saving it. ***Why do you need the path***? – Trevor Feb 21 '16 at 04:51
  • So there's no way to display a image from the user's original file path?@Codexer – Jeosiyy Chu Feb 21 '16 at 04:53
  • If user keeps uploading photos, then the photos uploaded all go to DB, I m trying to avoid this @Codexer – Jeosiyy Chu Feb 21 '16 at 04:54
  • You are putting them there, why store them first? Don't store them... – Trevor Feb 21 '16 at 04:55
  • @Codexer which means.....? Sry, I'm kind of new to this – Jeosiyy Chu Feb 21 '16 at 04:58
  • 1
    Also that is ***not how `FileUpload` works***, it's a security reason. When a user uploads a file, it is effectively being transferred from the client's computer to the server hosting your application. From there you can save it off and then access that file... No need to go to database first :) So you can read the stream `(FileUpload.PostedFile.InputStream)` **or** `FileUpload.PostedFile.SaveAs` save it and then access it. – Trevor Feb 21 '16 at 04:58
  • Oh I got it! That was my mistake, was trying to ask on 'How to detect original file path before storing it into the folder directory of the server hosting'. But seems like there'no no way to do this? @Codexer – Jeosiyy Chu Feb 21 '16 at 05:02
  • 1
    ***No the control wont give it to you, it handles this*** besides you can't access it :) Please see implementation [**here**](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas(v=vs.110).aspx) – Trevor Feb 21 '16 at 05:03
  • Alright, that's a lot of thanks! @Codexer :D – Jeosiyy Chu Feb 21 '16 at 05:05
  • Welcome, happy coding! – Trevor Feb 21 '16 at 05:08

1 Answers1

1

That is not how FileUpload works (that control handles this), it's a security reason. When a user uploads a file, it is effectively being transferred from the client's computer to the server hosting your application. From there you can save it off and then access that file... No need to go to database first :) So you can read the stream (FileUpload.PostedFile.InputStream) or FileUpload.PostedFile.SaveAs save it and then access it.

Please see more here: Get full path of a file with FileUpload Control

Community
  • 1
  • 1
Trevor
  • 7,777
  • 6
  • 31
  • 50