Esempio n. 1
0
            public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
            {
                var request = controllerContext.RequestContext.HttpContext.Request;
                var formUpload = request.Files.Count > 0;

                // find filename
                var xFileName = request.Headers["X-File-Name"];
                var qqFile = request["qqfile"];
                var fileBase = request.Files[0];
                if (fileBase != null)
                {
                    var formFilename = formUpload ? fileBase.FileName : null;

                    var upload = new FineUpload
                                 {
                                     Filename = xFileName ?? qqFile ?? formFilename,
                                     InputStream = formUpload ? fileBase.InputStream : request.InputStream
                                 };

                    return upload;
                }
                return null;
            }
Esempio n. 2
0
        public FineUploaderResult _UploadNewsPicture(FineUpload upload)
        {
            const string path = "/Images";

            var randomName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + Path.GetExtension(upload.Filename);
            var filePath = Server.MapPath(Path.Combine(path, PathHelper.NewsPicture(randomName)));
            try
            {
                upload.SaveAs(filePath);
            }
            catch (Exception ex)
            {
                return new FineUploaderResult(false, error: ex.Message);
            }

            return new FineUploaderResult(true, new { fullfilename = path + "/" + PathHelper.NewsPicture(randomName), filename = randomName });
        }