angular-mat-table-crud icon indicating copy to clipboard operation
angular-mat-table-crud copied to clipboard

image upload

Open ilos67 opened this issue 5 years ago • 2 comments

Hi, I must say it's almost what I was looking for. If it is possible to add with an image it will super for me. Is it possible to add and update with a image upload in this project? Thank you

ilos67 avatar Sep 19 '19 16:09 ilos67

Heya @ilos67, Image upload relies heavily on the backend, mostly where to store image one it's been uploaded. Once you sort that adding upload views on frontend is easy!

marinantonio avatar Sep 21 '19 22:09 marinantonio

Hi, My Controller is; [HttpPost] [Route("SaveGroupPicture")] [AllowAnonymous] public async Task<ActionResult> SaveGroupPicture(IFormFile picture) { var fileName = Guid.NewGuid().ToString() + Path.GetExtension(picture.FileName);

        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/mainGroupPictures", fileName);

        using (var stream = new FileStream(path, FileMode.Create))
        {
            await picture.CopyToAsync(stream);
        };
        var result = new
        {
            path = "http://" + Request.Host + "/mainGroupPictures/" + fileName
        };

        return Ok(result);
    }

Frontend is; handleFileInput(file: FileList) { this.fileData = file.item(0);

var reader = new FileReader();
reader.onload = (event : any) => {
  this.picture = event.target.result;
}
reader.readAsDataURL(this.fileData);

    let formData = new FormData();
formData.append("picture", this.fileData)

   this.mainGroupService.saveMainGroupPicture(formData).subscribe(result => {

 this.picture = result.path;
 console.log(this.picture);
});

}

I couldn't set picture property.

If you could help this, I will be thankfull to you.

Thanks again

ilos67 avatar Sep 23 '19 03:09 ilos67