How don't save upload file on disk
How don't save upload file on disk
SuiteProG
Posts: 26Questions: 3Answers: 0
Hello,
I use DataTable editor with c#.NET library.
One on my fields it's "upload" type.
I don't want save the file in disk, I want directly save content in my DB.
What's method for this ?
This code save content on my DB and on my disk :
var response = new Editor(db, "users")
.Model<UploadModel>()
.TryCatch(false)
.Field(new Field("image")
.SetFormatter(Format.IfEmpty(null))
.Upload(new Upload(request.PhysicalApplicationPath + @"uploads\__ID____EXTN__")
.Db("files", "id", new Dictionary<string, object>
{
{"web_path", Upload.DbType.WebPath},
{"system_path", Upload.DbType.SystemPath},
{"filename", Upload.DbType.FileName},
{"filesize", Upload.DbType.FileSize},
{"content", Upload.DbType.ContentBinary},
})
.DbClean(data =>
{
foreach (var row in data)
{
// Do something;
}
return true;
})
.Validator(Validation.FileSize(500000, "Max file size is 500K."))
.Validator(Validation.FileExtensions( new [] {"jpg", "png", "gif"}, "Please upload an image."))
)
)
.Process(request)
.Data();
I try Upload(null) by don't work.
Thanks,
This discussion has been closed.
Answers
Hi,
Don't pass anything to the
new Upload()
constructor. That should mean that it doesn't write the file to the file system itself.Allan
Hi Allan,
Thanks for your reply.
When I use
new Upload()
, I have a NullReferenceException with this stacktrace :My new code :
Hi @allan,
I always have a NullReferenceException with no parameters Upload constructor.
Cheers
Sorry about that. A bug in the library if there is no string action it assumes there will be a function action. Which isn't the case here. I've committed a fix and you can either build the dll from that repo or I can send you an update if you prefer.
Regards,
Allan
Hi @allan,
Thanks for your reply.
If you can send an update to me, I prefer
Cheers
Hi @allan
Can I have update dll ?
Cheers
Oops - sorry! I completely lost track of this thread. I've sent you a PM with a link for the updated dll.
Allan