[NopCommerce 3.1] asp.net mvc uses jQuery from. js to upload user portraits

Source: Internet
Author: User

/// <Summary> /// ajax uploads the user's avatar /// </summary> /// <param name = "uploadedFile"> </param> /// <returns> </returns> [HttpPost] public string AjaxUploadAvatar (HttpPostedFileBase uploadedFile) {string message = string. empty; var customer = _ workContext. currentCustomer; try {var customerAvatar = _ pictureService. getPictureById (customer. getAttribute <int> (SystemCustomerAttributeNames. avatarPictureId); if (up LoadedFile! = Null )&&(! String. isNullOrEmpty (uploadedFile. fileName) {int avatarMaxSize = _ customerSettings. avatarMaximumSizeBytes; if (uploadedFile. contentLength> avatarMaxSize) {message = string. format (_ localizationService. getResource ("Account. avatar. maximumUploadedFileSize "), avatarMaxSize); return message;} 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); message = _ pictureService. getPictureUrl (customer. getAttribute <int> (SystemCustomerAttributeNames. avatarPictureId), _ mediaSettings. avatarPictureSize, false); return "1 |" + message;} catch (Exception exc) {message = exc. message; return message ;}}

View code: Avatar. cshtml

* Select an image on your computer to modify the current Avatar. The image is being uploaded. Please wait... @ T ("Account. Avatar. UploadRules ")

I will not talk about anything else. Welcome to join the group discussion with NopCommerce.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.