本文整理匯總了C#中System.Web.HttpPostedFileBase.GetPictureBits方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpPostedFileBase.GetPictureBits方法的具體用法?C# HttpPostedFileBase.GetPictureBits怎麽用?C# HttpPostedFileBase.GetPictureBits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.HttpPostedFileBase
的用法示例。
在下文中一共展示了HttpPostedFileBase.GetPictureBits方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InsertPicture
public ActionResult InsertPicture(string authToken, HttpPostedFileBase httpPostedFile)
{
//Workaround for flash cookie bug
//http://stackoverflow.com/questions/1729179/uploadify-session-and-authentication-with-asp-net-mvc
//http://geekswithblogs.net/apopovsky/archive/2009/05/06/working-around-flash-cookie-bug-in-asp.net-mvc.aspx
var ticket = FormsAuthentication.Decrypt(authToken);
if (ticket == null)
return Json(new { success = false, error = "No token provided"});
var identity = new FormsIdentity(ticket);
if (!identity.IsAuthenticated)
return Json(new { success = false, error = "User is not authenticated" });
var customer = ((FormsAuthenticationService)_authenticationService).GetAuthenticatedCustomerFromTicket(ticket);
if (!_permissionService.Authorize(StandardPermissionProvider.UploadPictures, customer))
return Json(new { success = false, error = "User doesn't have required permissions" });
byte[] pictureBinary = httpPostedFile.GetPictureBits();
//TODO: find a better solution: little hack here
//'Uploadify' component uploads all files with "application/octet-stream" mime type
//that's why we manually update it here
//http://www.sfsu.edu/training/mimetype.htm
string contentType = httpPostedFile.ContentType;
string fileExtension = Path.GetExtension(httpPostedFile.FileName);
if (!String.IsNullOrEmpty(fileExtension))
fileExtension = fileExtension.ToLowerInvariant();
switch (fileExtension)
{
case ".bmp":
contentType = "image/bmp";
break;
case ".gif":
contentType = "image/gif";
break;
case ".jpeg":
case ".jpg":
case ".jpe":
case ".jfif":
case ".pjpeg":
case ".pjp":
contentType = "image/jpeg";
break;
case ".png":
contentType = "image/png";
break;
case ".tiff":
case ".tif":
contentType = "image/tiff";
break;
default:
break;
}
var picture = _pictureService.InsertPicture(pictureBinary, contentType, null, true);
return Json(new { success = true, pictureId = picture.Id, imageUrl = _pictureService.GetPictureUrl(picture, 100) });
}
示例2: UploadAvatar
public ActionResult UploadAvatar(CustomerAvatarModel model, HttpPostedFileBase uploadedFile)
{
if (!IsCurrentUserRegistered())
return new HttpUnauthorizedResult();
if (!_customerSettings.AllowCustomersToUploadAvatars)
return RedirectToRoute("CustomerInfo");
var customer = _workContext.CurrentCustomer;
model.NavigationModel = GetCustomerNavigationModel(customer);
model.NavigationModel.SelectedTab = CustomerNavigationEnum.Avatar;
if (ModelState.IsValid)
{
try
{
var customerAvatar = _pictureService.GetPictureById(customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId));
if ((uploadedFile != null) && (!String.IsNullOrEmpty(uploadedFile.FileName)))
{
int avatarMaxSize = _customerSettings.AvatarMaximumSizeBytes;
if (uploadedFile.ContentLength > avatarMaxSize)
throw new NasException(string.Format(_localizationService.GetResource("Account.Avatar.MaximumUploadedFileSize"), avatarMaxSize));
byte[] customerPictureBinary = uploadedFile.GetPictureBits();
if (customerAvatar != null)
customerAvatar = _pictureService.UpdatePicture(customerAvatar.Id, customerPictureBinary, uploadedFile.ContentType, null, true);
else
customerAvatar = _pictureService.InsertPicture(customerPictureBinary, uploadedFile.ContentType, null, true);
}
int customerAvatarId = 0;
if (customerAvatar != null)
customerAvatarId = customerAvatar.Id;
_genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.AvatarPictureId, customerAvatarId);
model.AvatarUrl = _pictureService.GetPictureUrl(
customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId),
_mediaSettings.AvatarPictureSize,
false);
return View(model);
}
catch (Exception exc)
{
ModelState.AddModelError("", exc.Message);
}
}
//If we got this far, something failed, redisplay form
model.AvatarUrl = _pictureService.GetPictureUrl(
customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId),
_mediaSettings.AvatarPictureSize,
false);
return View(model);
}
示例3: Info
public ActionResult Info(VendorInfoModel model, HttpPostedFileBase uploadedFile)
{
if (!_workContext.CurrentCustomer.IsRegistered())
return new HttpUnauthorizedResult();
if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo)
return RedirectToRoute("CustomerInfo");
Picture picture = null;
var pictureSize = _mediaSettings.AvatarPictureSize;
if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
{
try
{
var contentType = uploadedFile.ContentType;
var vendorPictureBinary = uploadedFile.GetPictureBits();
picture = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);
}
catch (Exception)
{
ModelState.AddModelError("", _localizationService.GetResource("Account.VendorInfo.Picture.ErrorMessage"));
}
}
var vendor = _workContext.CurrentVendor;
var prevPicture = _pictureService.GetPictureById(vendor.PictureId);
if (ModelState.IsValid)
{
var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
vendor.Name = model.Name;
vendor.Email = model.Email;
vendor.Description = description;
if (picture != null)
{
vendor.PictureId = picture.Id;
if (prevPicture != null)
_pictureService.DeletePicture(prevPicture);
}
//update picture seo file name
UpdatePictureSeoNames(vendor);
_vendorService.UpdateVendor(vendor);
//notifications
if (_vendorSettings.NotifyStoreOwnerAboutVendorInformationChange)
_workflowMessageService.SendVendorInformationChangeNotification(vendor, _localizationSettings.DefaultAdminLanguageId);
return RedirectToAction("Info");
}
//If we got this far, something failed, redisplay form
model.PictureUrl = _pictureService.GetPictureUrl(prevPicture, pictureSize);
return View(model);
}
示例4: ApplyVendorSubmit
public ActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, HttpPostedFileBase uploadedFile)
{
if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
return RedirectToRoute("HomePage");
if (!_workContext.CurrentCustomer.IsRegistered())
return new HttpUnauthorizedResult();
//validate CAPTCHA
if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
{
ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
}
int pictureId = 0;
if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
{
try
{
var contentType = uploadedFile.ContentType;
var vendorPictureBinary = uploadedFile.GetPictureBits();
var picture = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);
if (picture != null)
pictureId = picture.Id;
}
catch (Exception)
{
ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
}
}
if (ModelState.IsValid)
{
var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
//disabled by default
var vendor = new Vendor
{
Name = model.Name,
Email = model.Email,
//some default settings
PageSize = 6,
AllowCustomersToSelectPageSize = true,
PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions,
PictureId = pictureId,
Description = description
};
_vendorService.InsertVendor(vendor);
//search engine name (the same as vendor name)
var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true);
_urlRecordService.SaveSlug(vendor, seName, 0);
//associate to the current customer
//but a store owner will have to manually add this customer role to "Vendors" role
//if he wants to grant access to admin area
_workContext.CurrentCustomer.VendorId = vendor.Id;
_customerService.UpdateCustomer(_workContext.CurrentCustomer);
//update picture seo file name
UpdatePictureSeoNames(vendor);
//notify store owner here (email)
_workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
vendor, _localizationSettings.DefaultAdminLanguageId);
model.DisableFormInput = true;
model.Result = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
return View(model);
}
//If we got this far, something failed, redisplay form
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
return View(model);
}