public JsonResult ProcessSingleUploads(App app, HttpPostedFileBase file, int galleryId, UploadProcessor uploadProcessorSepecific) { if (file != null && app.UploadGuid != null) { //look for cache if sequence exist before var fileName = app.UploadGuid.ToString(); if (file.ContentLength > 0) { // first save gallery and temp record. //upload the image uploadProcessorSepecific.UploadFile(file, fileName, 0, true, true); //successfully uploaded now save a gallery info var galleryCategory = db.GalleryCategories.Find(galleryId); var gallery = db.Galleries.FirstOrDefault( n => n.UploadGuid == app.UploadGuid && n.GalleryCategoryID == galleryCategory.GalleryCategoryID); if (gallery == null) { gallery = new Gallery(); gallery.GalleryID = Guid.NewGuid(); gallery.UploadGuid = app.UploadGuid; gallery.Title = app.AppName; gallery.Extension = UploadProcessor.GetExtension(file); gallery.GalleryCategoryID = galleryCategory.GalleryCategoryID; gallery.Sequence = 0; db.Galleries.Add(gallery); // try to add a temp record as well. var tempUpload = new TempUpload(); tempUpload.TempUploadID = Guid.NewGuid(); tempUpload.UserID = UserManager.GetLoggedUserId(); tempUpload.GalleryID = gallery.GalleryID; tempUpload.RelatingUploadGuidForDelete = app.UploadGuid; db.TempUploads.Add(tempUpload); db.SaveChanges(); } // resize //new Thread(() => { uploadProcessorSepecific.ResizeImageAndProcessImage(gallery, galleryCategory); uploadProcessorSepecific.RemoveTempImage(gallery); //}).Start(); } return(Json(new { isUploaded = true, message = "successfully done" }, "text/html")); } return(Json(new { isUploaded = false, message = "No file send." }, "text/html")); }
protected void Button1_Click(object sender, EventArgs e) { //add file if (FileUpload1.HasFile == true) { //save to temp TempUpload objTemp = new TempUpload(FileUpload1); string pathtemp = objTemp.SaveFile(); string pathreal = string.Format(Constant.pathserverUpload, FileUpload1.FileName); _objFile.Add(new ListFile() { _fileid = _objFile.Count + 1, _filename = FileUpload1.FileName, _filestream = FileUpload1.PostedFile.InputStream, _pathtemp = pathtemp, _pathreal = pathreal, _status = "N" }); Repeater1.DataSource = _objFile; Repeater1.DataBind(); } }
public async Task <JsonResult> UploadGallery(App app, IEnumerable <HttpPostedFileBase> galleries) { if (galleries != null && app.UploadGuid != null) { //look for cache if sequence exist before var nextSequence = GetSequenceNumber(app.UploadGuid); var nextCount = GetHowManyGalleryImageExist(app.UploadGuid); if (nextCount > AppVar.Setting.GalleryMaxPictures) { ResetSessionForUploadSequence(app.UploadGuid); return(Json(new { isUploaded = false, uploadedFiles = 0, message = "You are out of your limit." }, "text/html")); } var fileName = app.UploadGuid.ToString(); var firstTime = true; var countDone = 0; foreach (var file in galleries) { if (file.ContentLength > 0) { // first save gallery and temp record. if (!firstTime) { nextSequence = GetSequenceNumber(app.UploadGuid); nextCount = GetHowManyGalleryImageExist(app.UploadGuid); if (nextCount > AppVar.Setting.GalleryMaxPictures) { ResetSessionForUploadSequence(app.UploadGuid); return (Json( new { isUploaded = true, uploadedFiles = countDone, message = "You are out of your limit." }, "text/html")); } } else { firstTime = false; } //upload app-details page gallery image Statics.UProcessorGallery.UploadFile(file, fileName, nextSequence, true, true); //successfully uploaded now save a gallery info var galleryCategory = await db.GalleryCategories.FindAsync(GalleryCategoryIDs.AppPageGallery); //var thumbsCategory = await db.GalleryCategories.FindAsync(GalleryCategoryIDs.GalleryIcon); var gallery = await db.Galleries.FirstOrDefaultAsync( n => n.UploadGuid == app.UploadGuid && n.GalleryCategoryID == galleryCategory.GalleryCategoryID && n.Sequence == nextSequence); // saving in the database if (gallery == null) { // we didn't get the error // image sequence and guid is correct. gallery = new Gallery(); gallery.GalleryID = Guid.NewGuid(); gallery.UploadGuid = app.UploadGuid; if (!string.IsNullOrEmpty(app.AppName)) { gallery.Title = app.AppName + "-" + nextSequence; } gallery.Extension = UploadProcessor.GetExtension(file); gallery.GalleryCategoryID = galleryCategory.GalleryCategoryID; gallery.Sequence = nextSequence; db.Galleries.Add(gallery); // try to add a temp record as well. var tempUpload = new TempUpload(); tempUpload.TempUploadID = Guid.NewGuid(); tempUpload.UserID = UserManager.GetLoggedUserId(); tempUpload.GalleryID = gallery.GalleryID; tempUpload.RelatingUploadGuidForDelete = app.UploadGuid; db.TempUploads.Add(tempUpload); await db.SaveChangesAsync(); } // resize //new Thread(() => { // resize app-details page gallery image Statics.UProcessorGallery.ResizeImageAndProcessImage(gallery, galleryCategory); //var source = "~/Uploads/Images/" + Variables.ADDITIONAL_ROOT_GALLERY_LOCATION + // UploadProcessor.GetOrganizeNameStatic(gallery, true, true); //var target = "~/Uploads/Images/" + Variables.ADDITIONAL_ROOT_GALLERY_ICON_LOCATION + // UploadProcessor.GetOrganizeNameStatic(gallery, true); // #apps detail page gallery thumbs generate //Statics.uProcessorGallery.ResizeImageAndProcessImage(source, target, thumbsCategory.Width, // thumbsCategory.Height, gallery.Extension); var source = "~/Uploads/Images/" + Variables.AdditionalRootGalleryLocation + UploadProcessor.GetOrganizeNameStatic(gallery, true, true); //removing temp image what was exact uploaded after resizing it. if (FileSys.Exists(Statics.UProcessorGallery.VirtualPathtoAbsoluteServerPath(source))) { // if processed image exist then remove the temp. Statics.UProcessorGallery.RemoveTempImage(gallery); } countDone++; //}).Start(); } } var countUploaded = galleries.Count(); return (Json( new { isUploaded = true, uploadedFiles = countUploaded, message = "+" + countUploaded + " files successfully done." }, "text/html")); } return(Json(new { isUploaded = false, uploadedFiles = 0, message = "No file send." }, "text/html")); }