tags:

views:

160

answers:

1

how can i upload videos in my mysql database using asp.net mvc?

view:

<form method="post" enctype="multipart/form-data" action="<%=url.action("VideosInsert") %>">
<%Using Html.BeginForm%>
<p>
<label for="videourl">Browse url :</label>
<input type="file" name="video" />
</p>
<p>
<label for="caption">Caption :</label>
<%=Html.TextBox("caption", String.Empty, New With {Key .size = 100})%>
</p>
<p>
<label for="eventDate">Date of Event:</label>
<%=Html.TextBox("eventDate")%>
</p>
<p>
<label for="category">Category :</label>
<%=Html.TextBox("category")%>
</p>
<p>
<%=Html.CheckBox("feature")%>
<label for="feature">Feature</label>
</p>
<input type="submit" name="uploadvideo" value="Upload Video" />
<%End Using%>
</form>

Controller:

Imports System.IO

Public Class AdministrationController
    Inherits Global.System.Web.Mvc.Controller
    Private dVideos As New ClassVideosConnection

   <AcceptVerbs(HttpVerbs.Post)> _
    Function VideosInsert(ByVal video As HttpPostedFileBase, ByVal caption As String, ByVal eventDate As String, ByVal category As Integer, ByVal feature As Boolean) As ActionResult

        //the code goes here, i think

        dVideos.videoInsert(url:=video.FileName, caption:=caption, eventDate:=eventDate, IDcat:=category, featured:=dfeature)
        Return View()
    End Function
    End Class

Model:

Imports Microsoft.VisualBasic
Imports System.Data

Public Class ClassVideosConnection
Inherits ClassConnection

    Public Sub videoInsert(ByVal url As String, ByVal caption As String, ByVal eventDate As Date, ByVal IDcat As Integer, ByVal featured As Integer)
        Dim insert As String = String.Format("INSERT INTO videos(vidURL, vidCaption, vidEvent, IDcategory, vidFeatured) VALUES  ('{0}','{1}','{2}','{3}','{4}')", url, caption, eventDate, IDcat, featured)
        UpdateData(insert)
    End Sub
 End Class

i don't know if this is correct but this is the syntax i used in uploading images.. thank you in advance!

+1  A: 

The problem with your code is that you are opening the form twice ( with the form tag and then with the Html.BeginForm call.

You need to pass the enctype="multipart/form-data" into the html attributes via a call like

Html.BeginForm(action,controller, FormMethod.Post, new { enctype="multipart/form-data"})

although I am not sure of the exact syntax for VB

Neal
I would just get rid of the Html.BeginForm() and End Using. <form></form> is clearer to me.
Lance Fisher