using Plupload with ASP.NET/C#

后端 未结 2 1522
Happy的楠姐
Happy的楠姐 2020-12-07 11:15

UPDATE

I was able to get everything to work properly and I just wanted to post back with the updated code. I used Darin Dimitrov\'s suggestion on using a separate

2条回答
  •  Happy的楠姐
    2020-12-07 11:48

    Here is a VB example of an ashx file for pluploader.

    Thanks to @@Darin Dimitrov Who suggested this. Its the best solution ever with many fall backs like silverlight,flash.. etc.. its mega!

    I did not find any VB examples so i converted it my self- tested and works! With chunking!

    To add a ashx file to your website in VisualStudio. Right click the website

    website > add new item > generic handler

    This is all in one page no need for code behind. Just call this from the pluplaod plugin

    <%@ WebHandler Language="VB" Class="upload" %>
    
    Imports System
    Imports System.IO
    Imports System.Web
    
    
    Public Class upload : Implements IHttpHandler
    
    
        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("~/uploads")
            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")
        End Sub
    
        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property
    
    End Class
    

提交回复
热议问题