public void Ajax_Thumb() { try { AjaxReceiver _receive = new AjaxReceiver(this.HttpContext, "imgsouce/origin"); //接收文件成功 _receive.OnSuccess = (data) => { //接收文件成功后,自动生成缩略图 // 大图 ThumbnailHandle _thumb = new ThumbnailHandle(data, "big", 920); _thumb.AutoHandle(); string big = _thumb.GetRelativeName(); Write("大图位置:" + big); //小图 _thumb.Width = 320; _thumb.Folder = "small"; _thumb.AutoHandle(); string small = _thumb.GetRelativeName(); Write("小图位置:" + small); data.Data = new { big = big, small = small }; //此处,有需要的情况下,执行数据库操作 Write(string.Format("新文件名{0},旧文件名{1}", data.NewName, data.OldName)); }; _receive.DoWork(); } catch (Exception ex) { throw ex; } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); //配置上传 UploadHandle.ServerInfo.SitePath = env.WebRootPath; //使用wwwroot作为根目录 //绑定WebScoket处理 ,指定websocket 方式放在外边了 app.Map("/common/socket", (con) => { con.UseWebSockets(); UploadHandle.Receiver.Map(con); }); //绑定WebSocket处理,接收成功后,生成缩略图 app.Map("/common/socket_thumb", (con) => { con.UseWebSockets();//启用webscoket con.Use((ctx, n) => { Receiver _receive = new Receiver(ctx, "imgdata/origin"); _receive.OnSuccess += (data) => { //接收文件成功后,自动生成缩略图 // 大图 ThumbnailHandle _thumb = new ThumbnailHandle(data, "big", 920); _thumb.AutoHandle(); string big = _thumb.GetRelativeName(); //小图 _thumb.Width = 320; _thumb.Folder = "small"; _thumb.AutoHandle(); string small = _thumb.GetRelativeName(); data.Data = new { big = big, small = small }; //此处,有需要的情况下,执行数据库操作 }; return(_receive.DoWork()); }); }); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); //配置上传 UploadHandle.ServerInfo.SitePath = env.WebRootPath; //使用wwwroot作为根目录 //绑定WebScoket处理 // app.Map("/common/socket", UploadHandle.Receiver.Map); //绑定WebSocket处理,接收成功后,生成缩略图 app.Map("/common/socket_thumb", (con) => { con.UseWebSockets();//启用webscoket con.Use((ctx, n) => { Receiver _receive = new Receiver(ctx, "imgdata/origin"); _receive.OnSuccess += (data) => { //接收文件成功后,自动生成缩略图 // 大图 ThumbnailHandle _thumb = new ThumbnailHandle(data, "big", 920); _thumb.AutoHandle(); string big = _thumb.GetRelativeName(); CommonController.Write("大图位置:" + big); //小图 _thumb.Width = 320; _thumb.Folder = "small"; _thumb.AutoHandle(); string small = _thumb.GetRelativeName(); CommonController.Write("小图位置:" + small); data.Data = new { big = big, small = small }; //此处,有需要的情况下,执行数据库操作 CommonController.Write(string.Format("新文件名{0},旧文件名{1}", data.NewName, data.OldName)); }; return(_receive.DoWork()); }); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }