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.



  • 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!



最新内容

  • 问题

    I am getting crazy with snakemake. I tried all types of ways, using config file etc, but nothing works and I cannot understand exactly how to detect the error checking line by line.

    HISAT2_INDEX_PREFIX = \"/media/jim/Elements/Happy/index/genome_chromosomes\" SAMPLES, *_=glob_wildcards(\'/media/jim/Elements/Happy/test/tissue/trimmed/{sample}_1.fastq.gz\') rule all: input: expand(\"{sample}.bam\", sample=SAMPLES) rule hisat2: input: hisat2_index=expand(f\"{HISAT2_INDEX_PREFIX}.{{ix}}.ht2l\", ix=range(1, 8)), fastq1=\"/media/jim/Elements/Happy/test/tissue/trimmed/{sample}_1.fastq.gz\", fastq2=\"/media/jim/Elements/Happy/test/tissue/trimmed/{sample}_2.fastq.gz\" output: bam = \"{sample}.bam\", txt = \"{sample}.txt\", log: \"/snakemake_log.txt\" threads: 8 shell: \"hisat2 -p {threads} -x {HISAT2_INDEX_PREFIX}\" \" -1 {input.fastq1} -2 {input.fastq2} --summary-file {output.txt} |\" \"samtools sort -@ {threads} -o {output.bam}\"

    Now the error I get is:

    SyntaxError in line 11 of /media/jim/Elements/Happy/test/Snakefile: invalid syntax

    The error might be some small thing, but I cannot understand which...... The problem is that I have many tissues, so I have to make working at least this simple example...

    回答1:

    1

    A couple of things...

    log: "/snakemake_log.txt" should contain the same wildcards as the other directives. E.g. log: "/{sample}.snakemake_log.txt" otherwise snakemake doesn't know where to write the sample specific logs I think the string formatting with f"..." has been introduced in python 3.6. Maybe you have python < 3.6?

    share|improve this answer

    answered Nov 7 at 9:49

    darioberdariober 2,7051515 silver badges2525 bronze badges

    yes, I am using python 3.5.1 I think...but I have python 3.6 installed, is there a way: a. to substitute f"..." b. to indicate which python to use?thanksss so much! – user3224522 Nov 7 at 9:59

    I usually use virtual environment: virtualenv -p python3 .venv then source .venv/bin/activate – user3224522 Nov 7 at 10:03

    1

    I would use a more portable string-formatting syntax. The old-fashioned style would be expand("%s.{ix}.ht2l" % HISAT2_INDEX_PREFIX, ix=range(1, 8)) – dariober Nov 7 at 10:05

    Wow, I hope it is running, at least it doesn't through an error!! – user3224522 Nov 7 at 11:35

    add a comment |

    read more
  • A couple of things...

    log: "/snakemake_log.txt" should contain the same wildcards as the other directives. E.g. log: "/{sample}.snakemake_log.txt" otherwise snakemake doesn't know where to write the sample specific logs I think the string formatting with f"..." has been introduced in python 3.6. Maybe you have python < 3.6?

    read more
  • I am getting crazy with snakemake. I tried all types of ways, using config file etc, but nothing works and I cannot understand exactly how to detect the error checking line by line.

    HISAT2_INDEX_PREFIX = \"/media/jim/Elements/Happy/index/genome_chromosomes\" SAMPLES, *_=glob_wildcards(\'/media/jim/Elements/Happy/test/tissue/trimmed/{sample}_1.fastq.gz\') rule all: input: expand(\"{sample}.bam\", sample=SAMPLES) rule hisat2: input: hisat2_index=expand(f\"{HISAT2_INDEX_PREFIX}.{{ix}}.ht2l\", ix=range(1, 8)), fastq1=\"/media/jim/Elements/Happy/test/tissue/trimmed/{sample}_1.fastq.gz\", fastq2=\"/media/jim/Elements/Happy/test/tissue/trimmed/{sample}_2.fastq.gz\" output: bam = \"{sample}.bam\", txt = \"{sample}.txt\", log: \"/snakemake_log.txt\" threads: 8 shell: \"hisat2 -p {threads} -x {HISAT2_INDEX_PREFIX}\" \" -1 {input.fastq1} -2 {input.fastq2} --summary-file {output.txt} |\" \"samtools sort -@ {threads} -o {output.bam}\"

    Now the error I get is:

    SyntaxError in line 11 of /media/jim/Elements/Happy/test/Snakefile: invalid syntax

    The error might be some small thing, but I cannot understand which...... The problem is that I have many tissues, so I have to make working at least this simple example...

    read more

最新主题

313
Online

339
Users

226.1k
Topics

379.5k
Posts

在线用户

推荐阅读

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