How to upload profile picture and update it in identity asp.net core 3



  • 问题

    I want to upload profile picture in identity user and update it in account management. if there is any post with good examples for asp.net core please give me links.

    回答1:

    0

    I did it myself with FileForm Method. First You Have to Add string property in User Class(https://docs.microsoft.com/en-us/aspnet/core/security/authentication/add-user-data?view=aspnetcore-3.0&tabs=visual-studio).

            public string Avatar { get; set; }
    
    

    and then, update the Manage/Index files by following the documentation. Now, How to create the file upload system? I did like the code below. but if i need to change something for security, please don't forget to help.

                        if (Input.Avatar != null)
                    {
                        string existfile = Path.Combine(hostingEnvironment.WebRootPath, "uploads", user.Avatar);
                        System.IO.File.Delete(existfile);
    
                    }
                    var uploads = Path.Combine(hostingEnvironment.WebRootPath, "uploads", "avatar");
                    var filePath = Path.Combine(uploads, fileName);
                    this.Image.CopyTo(new FileStream(filePath, FileMode.Create));
                    user.Avatar = fileName; // Set the file name
    
    

    GetUniqueFileName Class after the PostAsync class:

            private string GetUniqueName(string fileName)
        {
            fileName = Path.GetFileName(fileName);
            return Path.GetFileNameWithoutExtension(fileName)
                   + "_" + Guid.NewGuid().ToString().Substring(0, 4)
                   + Path.GetExtension(fileName);
        }
    
    

    You also have to add the IWebHostEnvironment dependency injection and update the cshtml form with multipart/form-data enctype. Don't forget to follow the .net documentation rules also. Good Luck!

    share|improve this answer

    answered 11 hours ago

    Mizu HaqueMizu Haque 133 bronze badges

    add a comment |



最新内容

  • I am receiving com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No value type configured for ObjectReader problem while executing below code

    Jackson version is jackson-databind-2.9.9.jar

    public <T> T parsingData(String body) {   try {     return getObjectMapper().reader().readValue(body);   } catch (IOException ioe) { ioe.printStackTrace();   } }

    Below exact Exception i\'m getting in printStackTrace and can find the String body which is exposed in the exception.

    com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No value type configured for ObjectReader at [Source: (String)\"{ \"timestamp\": \"2019-06-04T09:36:50.086+02:00\", \"path\": \"/api/check/85358/checking/246syb-f3f2-4756-91da-dae3e8ce774b/test/22462da-c4e2-45ca-bd27-246/rows/8bc3965a-ae22-4d7f-b770-262sgs24/port\", \"status\": 400, \"error\": \"Internal Server Error\", \"message\": \"[owner.firstName2:size:1:30, owner.lastName2:size:1:30]\", \"errorCode\": 200000 } \"; line: 1, column: 1]

    Updated: Could you please explain me why am i receiving this exception? Is this because that I haven\'t provide Class or TypeReference?

    read more
  • 问题

    I would like to match text in Spacy with the following pattern:

    If there is the word \"dénomination\" or \"denomination\", I want to match the next \'MISC\' entity (entity name from Spacy), whatever there is between the two.

    for example in:

    <pre class="\"lang-py" prettyprint-override="">``` text=\" Some texte about a company, company number: 254455, Dénomination\\n (entire name): NAME_OF_THE_COMPANY , \\n, some other informations of the... \" I\\'d like to extract \\"NAME\_OF\_COMPANY\\" which is recognize by Spacy as the entity MISC To get the entities with Spacy I do:

    <pre class=""lang-py" prettyprint-override="">```
    for txt in text_file:
    doc = nlp(txt)
    for token_french in doc_french:
    for ent in doc.ents:
    print(ent.label_, ent.text)

    But then I tried many pattern as the one below but without any success:

    <pre class="\"lang-py" prettyprint-override="">``` matcher=Matcher(nlp.vocab) pattern = [{\"REGEX\" : \"[D|d][é|e]nomination\\s{0,}\"},{\"REGEX\" : \"[A-Za-z\\n\\r\\s:)]{1,}\"},{\"ENT_TYPE\" : \"MISC\"}] matcher.add(\'company_name\', None, pattern) matches = matcher(doc) 回答1: ==== 0 A few things to keep in mind: - Each dict in the pattern corresponds to one token without surrounding whitespace. - You can match any number of intervening tokens with `{"OP": "*"}`. - It's useful to use `validate=True` with `Matcher()` to get more feedback when you're working on new patterns. I think your pattern might look more like:

    pattern = [{"LOWER": {"REGEX" : "d[é|e]nomination"}}, {"OP": "*"}, {"ENT_TYPE": "MISC"}]

    The Matcher looks at the whole document, so if you have a long document this will provide not only the next MISC but a match with "denomination" followed by every following MISC. You'd have to select the shortest match from the results separately. share|improve this answer answered Sep 14 at 8:26 aabaab 2,8411010 silver badges1414 bronze badges - Thank you for your tips. And this is my problem, it will look after every MISC after "denomination". Indeed, I just want the first occurence after "denomination". Any ideas? – Pier Smn Sep 17 at 7:11 add a comment |

    read more
  • A few things to keep in mind:

    Each dict in the pattern corresponds to one token without surrounding whitespace. You can match any number of intervening tokens with {"OP": "*"}. It's useful to use validate=True with Matcher() to get more feedback when you're working on new patterns.

    I think your pattern might look more like:

    pattern = [{"LOWER": {"REGEX" : "d[é|e]nomination"}}, {"OP": "*"}, {"ENT_TYPE": "MISC"}]

    The Matcher looks at the whole document, so if you have a long document this will provide not only the next MISC but a match with "denomination" followed by every following MISC. You'd have to select the shortest match from the results separately.

    read more

最新主题

推荐阅读

本站部分内容来自互联网,其发布内容言论不代表本站观点,如果其链接、内容的侵犯您的权益,烦请联系我们,我们将及时予以处理。
Powered by NodeBB | 备案号:宁ICP备15000671号