[.net] File Upload custom action

[.net] File Upload custom action

AxendoNLAxendoNL Posts: 6Questions: 2Answers: 0

In this topic https://datatables.net/forums/discussion/comment/196440/ I read this comment:

Hi Vincent,

Good to hear the patch worked - thanks for letting me know.

That particular method isn't possible I'm afraid. Instead what you need to do is update the newly created database row in your action function. You've got the id for the primary key, so something like:

editor.db().Update(
  "uploaded_files",
  new Dictionary<string, object>{
    {"web_path", myVar}
  },
  new Dictionary<string, object>{
    {"id", id}
  }
);

I am trying to do this, but it is not working, this is part of my code:

editor
.Field(new Field("CertificateId")
   .Upload(
       new Upload((file, id) => {
            var someVar = _blobStorageService.UploadBlobAsync(file.OpenReadStream(), "templates");

           editor.Db().Update(
             "Files",
             new Dictionary<string, object>{
                {"FilePath", someVar}
             },
             new Dictionary<string, object>{
                {"id", id}
             }
           );

           return id;
       })
       .Db("Files", "Id", new Dictionary<string, object>
       {
           {"FileName", Upload.DbType.FileName}
       })
       .Validator(
           Validation.FileExtensions(
               ["pdf"],
               "Alleen pdf files zijn toegestaan."))
       )
   .SetFormatter(Format.NullEmpty()));

How can I use a variable that is inside the upload action to update a field in the Files table?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin
    Answer ✓

    You need to query the database. What you have around line 7 - 15 looks like it should do that to me. Does it give any errors or anything?

    If you add .Debug(true) just before you do .Process(...) it will show the SQL being executed in the returned JSON. What does that result in?

    Allan

  • AxendoNLAxendoNL Posts: 6Questions: 2Answers: 0

    @allan
    Thank you very much for your quick reply! Adding the debug info really helped. Turned out The FilePath didn't allow for nulls so for the first row create it allready gave an error. Now everything is working fine thanks!

  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin

    Awesome. Thanks for posting back and great to hear you got it working!

    Allan

Sign In or Register to comment.