2011-09-16 35 views
1

我使用Plupload插件上傳多個圖像,因爲我們可以選擇在客戶端調整圖像大小,並且我想上傳具有原始大小的圖像並將它們保存到單獨的文件夾中,調整大小的圖像到另一個文件夾。如何使用plupload保存具有兩個不同尺寸的圖像

任何人都可以建議我如何進一步? 這裏是我的代碼:

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 

這是我的腳本代碼:

<script type="text/javascript"> 
    $(function() { 
     // Setup flash version 
     $("#flash_uploader").pluploadQueue({ 
      // General settings 
      runtimes: 'flash', 
      url: 'upload.ashx', 
      max_file_size: '10mb', 
      chunk_size: '1mb', 
      unique_names: true, 
      filters: [ 
     { title: "Image files", extensions: "jpg" } 
    ], 

      // Resize images on clientside if we can 
      resize: { width: 800, height: 600, quality: 90 }, 

      // Flash settings 
      flash_swf_url: 'js/plupload.flash.swf', 

      init: { StateChanged: function (up) { 
       // Called when the state of the queue is changed 
       if (up.state == plupload.STOPPED) { 
        $("#btnSubmit").removeAttr("disabled"); 
       } 
      } 
      } 

     }); 
    var uploader = $('#flash_uploader').pluploadQueue(); 
    uploader.bind('FileUploaded', function (up, file, res) { 
     $('#showfilelist').append("<div id=" + file.id + "><a href='uploads/" + file.target_name + "' target='_blank'><img src='uploads/" + file.target_name + "' border='0'/><br>" + file.name + "</a><br>(" + plupload.formatSize(file.size) + ") <span></span></div>"); 

}); 
}); 

</script> 

回答

2
// Resizing an image 
// Inputs [ new image size (Height,Width), Origial file path & name, new file path & name ] 

ResizeImage(int height,int width, string inputFile, string outputFile) 
{ 
      var img = Image.FromFile(inputFile); 
      Image imagThumb = null; 
      imagThumb = img.GetThumbnailImage(width, height, null, new IntPtr()); 
      imagThumb.Save(outputFile); 
} 

輸入和輸出文件可以從路徑訪問你保存圖像

eg.var input = Server.MapPath("~/images/imagename"); 
+0

謝謝您實際上回復這是一個處理程序,我們不能繼續這樣做,所以是否有任何可能性爲上​​述處理程序追加此代碼。 – coder

相關問題