0

Good day stack overflow,

I am trying to save pictures in my mysql database, i think i will use BLOB correct?

I am planning to update my mysql database that is already hosted online to support uploading and displaying pictures in my project in vb.net,

I know the easiest way to do saving picture in mysql database is by saving the picture in a directory and putting the path only in the database, but how about for online database that is hosted in the internet and does not have a working directory? I mean just the database itself?

How can i optimized the time access for the picture to load?

MjdeLima
  • 31
  • 9
  • Possible duplicate of [how to insert image in mysql database using vb.net and adodb connection](http://stackoverflow.com/questions/24924982/how-to-insert-image-in-mysql-database-using-vb-net-and-adodb-connection) – Alex B. Oct 22 '16 at 12:35

1 Answers1

0
 Protected Sub UpLoadThisFile(ByVal upload As FileUpload)
    If UpL1.HasFile Then
        Dim fileName As String = Path.GetFileName(UpL1.PostedFile.FileName)
        UpL1.PostedFile.SaveAs(Server.MapPath("~/AltImg2/") + fileName)
        UpImag.ImageUrl = ("~/AltImg2/") + fileName
        T8.Text = ("~/AltImg2/") + fileName
    Else
        T8.Text = "~/NOPic/noimage.jpg"
    End If
End Sub

 Protected Sub CheckImag()
    If UpL1.HasFile Then
        Dim ValidatFileTy As String() = {"bmb", "gif", "png", "jpg", "jpeg"}
        Dim Ext As String = System.IO.Path.GetExtension(UpL1.PostedFile.FileName)
        Dim isValidFile As Boolean = False
        For i As Integer = 0 To ValidatFileTy.Length - 1
            If Ext = "." & ValidatFileTy(i) Then
                isValidFile = True
            End If
        Next
        If Not isValidFile Then
            MsgLbl.Visible = True
            MsgLbl.ForeColor = Drawing.Color.Red
            MsgLbl.Text = String.Join(",", ValidatFileTy)
            Exit Sub
        Else
            UpLoadThisFile(UpL1)
        End If
    Else
        UpLoadThisFile(UpL1)
    End If
End Sub

and in button

 Protected Sub BTAddNew_Click(sender As Object, e As EventArgs) Handles BTAddNew.Click
    Try
        CheckImag()
        Insert()
        Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

but how about for online database that is hosted in the internet and does not have a working directory? yes you must use ~ ("~/AltImg2/").

Aladein
  • 184
  • 2
  • 13