Hi, I am creating a file storage system using .net core, here is a working example which u can test with postman this is my api controller
public async Task<EntityDto> UploadFile([FromForm] UploadFileInput input)
{
File file = ObjectMapper.Map<File>(input);
Stream stream = input.File.OpenReadStream();
var id = await _fileManager.UploadFileToAzure(file, stream, AbpSession.GetUserId());
return new EntityDto() { Id = id };
}
this is my DTO
[AutoMapTo(typeof(File))]
public class UploadFileInput
{
public string Description { get; set; }
public int ParentFolderID { get; set; }
[Required]
public IFormFile File { get; set; }
}
this is my file entity
[Table("Files")]
public class File : FullAuditedEntity, IOpenedAudited
{
public const int MaxNameLength = 256;
public const int MaxDescriptionLength = 64 * 1024; //64KB
[ForeignKey("UserId")]
public User User { get; set; }
public long UserId { get; set; }
[Required]
[MaxLength(MaxNameLength)]
public virtual string Name { get; set; }
[MaxLength(MaxDescriptionLength)]
public virtual string Description { get; set; }
public virtual long Length { get; set; }
public virtual string ContentType { get; set; }
public virtual string Extension { get; set; }
public virtual string Uri { get; set; }
public virtual string StoredFileName { get; set; }
[ForeignKey("ParentFolderId")]
public Folder ParentFolder { get; set; }
public int? ParentFolderId { get; set; }
public byte PublicPermissionLevel { get; set; }
[ForeignKey("OwnerUserId")]
public User OwnerUser { get; set; }
public long OwnerUserId { get; set; }
public long? LastOpenedUserId { get; set; }
public DateTime? LastOpenedTime { get; set; }
public bool IsTrashed { get; set; }
public virtual ICollection<FilePermission> FilePermissions { get; set; }
protected File()
{
IsTrashed = false;
PublicPermissionLevel = (byte)PermissionLevel.None;
this.FilePermissions = new HashSet<FilePermission>();
}
}
i do custom mapping to map my file dto to my file entity
Configuration.Modules.AbpAutoMapper().Configurators.Add(config =>
{
config.CreateMap<UploadFileInput, File>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.File.FileName))
.ForMember(dest => dest.ContentType, opt => opt.MapFrom(src => src.File.ContentType))
.ForMember(dest => dest.Length, opt => opt.MapFrom(src => src.File.Length));
});
and this is test with postman
I put the authorization bearer token into my header, in my body i post using form data,
Key Type Value
File File Choose your file here
Description Text Test Description
ParentFolderID Text 1
finally send a post request to your url eg. <a class="postlink" href="http://localhost:21021/api/services/app/FileService/UploadFile">http://localhost:21021/api/services/app ... UploadFile</a>
Yes thank you, it works now
My delete entity is not working, any possible reasons? I have tried Delete And DeleteAsync methods as well. This is the way I test it.
public void DeleteFile(EntityDto input)
{
var fileToBeDeleted = _fileRepository.Get(input.Id);
_fileRepository.DeleteAsync(fileToBeDeleted);
var deletedFile = _fileRepository.Get(input.Id);
}
I put a break point after var deletedFile, and check their values, but both fileToBeDeleted & deletedFile are equal in value. Am I doing something wrong? Thank you EDIT There are no error messages or exceptions occurring.
Hi,
Wow that's perfect, you guys are making steady progress! How do I contribute to the process of getting ABP 2.0 up and running, and also moving the templates over? Is there list of small to-dos, that I can make pull requests for? Thanks!
I wish to try ABP for my next project, and have downloaded the .NET Core 1.x template. However I notice it still targets the .NET Framework 4.6. Will there be any plans to target .NET Core 1.x framework? A neat feature of .NET Core is being platform independent, which is one my the requirements of my project.
If there is a plan for it, how should the community contribute?
Thanks.