I use Youtube API to upload videos on youtube. I read the documentation here, but there is one problem. I want to use FileUpload asp.net control, so users can easily upload file. But youtube api requires full path of the file and FileUpload control doesn't support it of security reasons. So I tried to solve it this way:
Dim fileName As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
FileUpload1.SaveAs(Server.MapPath("~/Uploads/") + System.IO.Path.GetFileName(FileUpload1.FileName))
Dim FullPath As String = Server.MapPath("~/Uploads/") + System.IO.Path.GetFileName(FileUpload1.FileName)
Dim newVideo As New Video()
newVideo.Title = "Test video"
newVideo.Tags.Add(New MediaCategory("Games", YouTubeNameTable.CategorySchema))
newVideo.Keywords = "test 1 , test 2"
newVideo.Description = "test 3 test 4"
newVideo.YouTubeEntry.[Private] = False
newVideo.Tags.Add(New MediaCategory("tag 1, tag 2", YouTubeNameTable.DeveloperTagSchema))
newVideo.YouTubeEntry.Location = New GeoRssWhere(37, -122)
newVideo.YouTubeEntry.MediaSource = New MediaFileSource(FullPath, FileUpload1.PostedFile.ContentType)
Dim createdVideo As Video = request.Upload(newVideo)
I save the vide file in Uploads folder in my application and then get the path by Server.MapPath
. It works like this on my computer, on localhost. But when it will be on web server (web hosting), it won't work.
How do you solve this problem with FileUpload in this certain case? Please help me, I've been searching for the answer for 3 days.