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