Topic: Integrating Plupload with ASP.NET 1.1 application

Hi,
I am trying to integrate the plupload application with our custom application which is developed in ASP.NET 1.1. but unfortunately am getting some javascript errors after following the steps mentioned in the examples section.

I am trying to use the HTML4 widget to upload multiple files from a custom aspx page into the database with a session id of the user to keep track of the batch of files uploaded.

Is there anyway I can get some documentation related to how to use the app with an ASP.NET 1.1 application.

Thanks,
Regrds,
Anir

Re: Integrating Plupload with ASP.NET 1.1 application

We don't include a .NET example might add one in the future. But since we use HTTP, multipart encoding and HTML/JS it should be easy to use the plupload component with any backend.

Re: Integrating Plupload with ASP.NET 1.1 application

Hi,

I can give you an asp.net backend solution with one restriction. Until now, i was not able to correctly catch all of the octet-stream chunks. If you change the component to upload all in one chunk and raise the upload-limit (maxrequestlength) it works fine.

Step 1:
Modifiy web.config to raise the upload limit:
<system.web>
<httpRuntime maxRequestLength="40960" /> <!--40960 = 40 MB-->
</system.web>

Step 2:
Remove the "chunk_size" option in your javascript-code.

Step 3:
Build a Backend-Page (for example upload.aspx)
Add the following Code to upload.aspx.vb:
Dim chunk As Integer = Request.QueryString("chunk")
Dim chunks As Integer = Request.QueryString("chunks")
Dim name As String = Request.QueryString("name")
name = name.Replace("/", "").Replace("'", "").Replace("\", "")
Dim filename As String = Request.PhysicalApplicationPath + "upload/" + name

If Request.ContentType = "application/octet-stream" Then
   If (Request.ContentLength > 0) Then
      Dim buffer As Byte()
      Dim br As New BinaryReader(Request.InputStream)
      buffer = br.ReadBytes(br.BaseStream.Length)
      br.Close()
      Dim binWriter As New BinaryWriter(File.Open(filename, FileMode.Create))
      binWriter.Write(buffer)
      binWriter.Close()
   End If
End If

As soon as i found out how to handle the chunks i will post a new code example.

A big thank to the plupload developers. This component ist great stuff.

Regards
Reto

Last edited by chase (2010-06-20 21:13:07)

Re: Integrating Plupload with ASP.NET 1.1 application

Here's an updated sample that handles chunking and multpart. It more or less matches functionality with the PHP sample.

        Dim chunk As Integer = Request.QueryString("chunk")
        Dim chunks As Integer = Request.QueryString("chunks")
        Dim name As String = Request.QueryString("name")
        If Not String.IsNullOrEmpty(name) Then name = name.Replace("/", "").Replace("'", "").Replace("\", "")
        Dim filename As String = Request.PhysicalApplicationPath + "upload/" + name

        Dim buffer As Byte() = Nothing
        Dim br As BinaryReader = Nothing
        
        If Request.ContentType = "application/octet-stream" AndAlso Request.ContentLength > 0 Then
            br = New BinaryReader(Request.InputStream)
        ElseIf Request.ContentType.Contains("multipart/form-data") AndAlso Request.Files("file") IsNot Nothing AndAlso Request.Files("file").ContentLength > 0 Then
            br = New BinaryReader(Request.Files("file").InputStream)
        End If

        If br IsNot Nothing Then
            buffer = br.ReadBytes(br.BaseStream.Length)
            br.Close()
            
            Try
                Dim mode As Integer = FileMode.Create
                    
                If chunk > 0 Then
                    mode = FileMode.Append
                End If
                    
                Dim binWriter As New BinaryWriter(File.Open(filename, mode))
                binWriter.Write(buffer)
                binWriter.Close()
                Response.Write("{'jsonrpc' : '2.0', 'result' : null, 'id' : 'id'}")
                    
            Catch ex As Exception
                Response.Write("{'jsonrpc' : '2.0', 'error' : {'code': 102, 'message': 'Unable to save file.'}, 'id' : 'id'}")
            End Try
            
        Else
            Response.Write("{'jsonrpc' : '2.0', 'error' : {'code': 101, 'message': 'Incorrect type.'}, 'id' : 'id'}")
        End If

Many thanks chase and Plupload devs. Only gripe is documentation.

Last edited by fubenkyou (2010-07-13 23:19:46)

Re: Integrating Plupload with ASP.NET 1.1 application

It is a very difficult task. I am also a .NET programmer. I hope I will give you a solution.

Re: Integrating Plupload with ASP.NET 1.1 application

Please see my post on this thread Plupload issue: .Net 3.5 c# implementation, should work just the same on 1.1