Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Upload Images after preview with generic handler

$
0
0

Hi every body :)

I create a image uploader with jquery and ASP generic handler!

when images select or drop,upload automatically start!

is there any way to start upload after click?

I mean at first user drop or select images(maybe remove some of them after preview) and finally click upload!

Thanks a lot!

aspx code:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"><script src="latestJs_1.11/jquery.min.js"></script><script src="DropzoneJs_scripts/dropzone.js"></script><link href="DropzoneJs_scripts/dropzone.css" rel="stylesheet" /></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><h4>Upload image using DropzoneJS in Asp.net C#.</h4><a title="For details Explanation click here" target="_blank" href="http://codepedia.info/2015/03/using-dropzone-js-file-image-upload-in-asp-net-webform-c/?github=tuts#">Click here for explaination</a><br /><br /><div id="dZUpload" class="dropzone"><div class="dz-default dz-message">
            Drop image here. </div></div><script type="text/javascript">$(document).ready(function () {
            console.log("Hello");
            Dropzone.autoDiscover = false;
            //Simple Dropzonejs $("#dZUpload").dropzone({
                maxFiles: 5,
                addRemoveLinks: true,
                success: function (file, response) {
                    var imgName = response;
                    file.previewElement.classList.add("dz-success");
                    console.log("Successfully uploaded :" + imgName);
                },
                error: function (file, response) {
                    file.previewElement.classList.add("dz-error");
                }
            });
        });</script><asp:Button ID="btnUpload" runat="server" Text="Upload" /></asp:Content>

handler code:

 public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string dirFullPath = HttpContext.Current.Server.MapPath("~/MediaUploader/");
            string[] files;
            int numFiles;
            files = System.IO.Directory.GetFiles(dirFullPath);
            numFiles = files.Length;
            numFiles = numFiles + 1;

            string str_image = "";

            foreach (string s in context.Request.Files)
            {
                HttpPostedFile file = context.Request.Files[s];
                string fileName = file.FileName;
                string fileExtension = file.ContentType;

                if (!string.IsNullOrEmpty(fileName))
                {
                    fileExtension = Path.GetExtension(fileName);
                    str_image = "MyPHOTO_" + numFiles.ToString() + fileExtension;
                    string pathToSave = HttpContext.Current.Server.MapPath("~/MediaUploader/") + str_image;
                    file.SaveAs(pathToSave);
                }
            }
            context.Response.Write(str_image);
        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>