(eight) Avatar upload

Source: Internet
Author: User

Steps:

1. Get the Avatar (file,contenttype,filename)

2. Save Avatar
2.1. Save avatar to the specified file directory
2.2. Set the user Picture path

Specific operation

In the user management of the Add, edit page, you can upload the user's avatar, the page of the Avatar field refers to the Type=file text field.

<input type= "File" name= "Headimg"/>

After that, Useraction receives the 3 basic attribute variables that the file needs to configure:

Save the Avatar file in the server's Upload/user directory, and the name of the file is renamed with the UUID. (Must rename: ① problem with duplicate name ② special character in display)

1 //working with Avatars2                 if(Headimg! =NULL){3                     //1. Save Avatar to Upload/user4                     //gets the absolute address of the saved path5String FilePath = Servletactioncontext.getservletcontext (). Getrealpath ("Upload/user");6String fileName = Uuid.randomuuid (). toString (). ReplaceAll ("-", "") + headimgfilename.substring ( Headimgfilename.lastindexof ("."));7                     //Copying Files8Fileutils.copyfile (Headimg,NewFile (FilePath, FileName));9                     Ten                     //2. Set the user picture path OneUser.setheadimg ("user/" +fileName); A}

(eight) Avatar upload

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.