Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7799093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:11:49+00:00 2026-06-02T00:11:49+00:00

I have built working VB.net code that uploads multiple images to the server using

  • 0

I have built working VB.net code that uploads multiple images to the server using Plupload. I am using an HTTPHandler (FileUpload.ashx) to do the uplading and want to add a SQL Statement that will insert each of the images File Names to my SQL Database. I have tried just adding the SQL to the Handler, but when I do I get 4 database entries for each iamge that is uploaded. I really dont understand why and need some guidance. Thanks for your time in advance.

Pertainant HANDLER code:

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

    Dim chunk As Integer = If(context.Request("chunk") IsNot Nothing, Integer.Parse(context.Request("chunk")), 0)
    Dim fileName As String = If(context.Request("name") IsNot Nothing, context.Request("name"), String.Empty)
    Dim fileUpload As HttpPostedFile = context.Request.Files(0)

    Dim uploadPath = context.Server.MapPath("Upload")
    Using fs = New FileStream(Path.Combine(uploadPath, fileName), If(chunk = 0, FileMode.Create, FileMode.Append))
        Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
        fileUpload.InputStream.Read(buffer, 0, buffer.Length)

        fs.Write(buffer, 0, buffer.Length)
    End Using
    context.Response.ContentType = "text/plain"
    context.Response.Write("Success")

EXP: SQL insert

        Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(DBCONN)
    Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand("W2_InsertPhoto " & fileName, conn)
    Dim rs As SqlClient.SqlDataReader
    conn.Open()
    rs = command.ExecuteReader()
    rs.Close()
    rs = Nothing
    conn.Close()
    conn = Nothing
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:11:51+00:00Added an answer on June 2, 2026 at 12:11 am

    If you are using chunks then make sure that you fire your SQL aster the last chunk has been saved

    For example.

      chunk = If(context.Request("chunk") IsNot Nothing, Integer.Parse(context.Request("chunk")), 0)
      chunks = If(context.Request("chunks") IsNot Nothing, Integer.Parse(context.Request("chunks")) - 1, 0) 
    
    
     If (chunk = chunks) Then
          'Upload is complete, Save to DB here or whatever
     end if
    

    -1 is used on CHUNKS because chunks is -1 from the last chunk, if that makes sense.

    To get the file name all you need to add in your handler.ashx is..

    fileName = If(context.Request("name") IsNot Nothing, context.Request("name"), String.Empty)
    

    In order to get unique fileName from Pluplaod across to your handler, you need to tell Plupload(on the client) to use unique names.

    var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            max_file_size: '20mb',
            url: '../handler.ashx',
            chunk_size: '100kb',
            unique_names: true,
            multipart_params: { imageType: $('#myDiv').attr("MyIMageType"), custom: 'This is static custom text' },
    

    In your handler you call the 'name' request again and you will have the unqie names that pluplaoder made.. also to request the data in the multipart you do as usual request

    PictureType = If(context.Request("imageType") IsNot Nothing, [Enum].Parse(GetType(PictureType), context.Request("imageType")), Nothing)
    
    
    Dim myCustom as String = If(context.Request("custom") IsNot Nothing, context.Request("custom"))
    

    In response to your SQL you need to encapsulate the file name withing ' otherwise spaces and special characters will break the SQLCommand, because SQL will think its another variable or command instead of treating it purely as a string. This is also a common problem for SQL Injection.. Allowing hackers to inject code because of code like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Essentially I have built a socket server that multiple clients can connect to and
I am working on windows. I have built a twitter application using the twitter
I have been working with a Windows Mobile 6 app that is built with
Does anyone have a working example of a video player built using Qt phonon?
I am using .net framework 4.0 and working on Web deployment Setup, I have
I have a .NET project that's always been built/run by/on 32 bit machines. I
I am working on a project that utilizes .Net API (several .Net DLLs) provided
I have a java project that I'm working on which was working until a
I have an ASP.net MVC2 application. In wich I'm using JQuery to alter all
I'm working on a .NET component that gets a set of data from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.