Editor - Upload
Editor - Upload
dpanscik
Posts: 202Questions: 47Answers: 0
I'm back having fun working with Editor.
I'm getting my head wrapped around what upload requires to function. Have two initial questions. Referencing the example found here.
https://editor.datatables.net/examples/advanced/upload-many.html
Does the parent database table require a field named "users.site"?
What is stored here? An string array of table ID numbers of the "files" table?
Thanks as always for your help.
David
This question has an accepted answers - jump to answer
Answers
Hi David,
If you click the "Server script" tab just below the table, it will show the controller code used, which will hopefully explain a few things.
It uses an Mjoin to create the one-to-many relationship. Each file that is assigned to a user is assigned as a record in the
users_files
table, which contains a reference to a user row and also to a file, providing the link between them.It doesn't use arrays in the database, although that is how the JSON data that is loaded on the client-side represents the data.
Allan
Thanks Allan. I see the strategy. users_files reference the parent table. I was thinking the parent table referenced the users_files table. Makes sense.
Next question. referring to the example found here;
https://editor.datatables.net/manual/net/upload
How does this code;
combine with this code?
seems like there is some "glue" missing here. But perhaps not...
Ah - you are using C#. Sorry I didn't realise that. This is the C# equivalent of the PHP controller from the link I gave above:
The upload information needs to be in the
Mjoin
.This is the documentation for
Mjoin
in .NET.Allan
perfect. thank you Allan. I'm going to dive in and ramble around and see what happens.
I have a 4 more questions to help wrap my head around how this is supposed to work.
(1) Does this code make a (for lack of a better term) virtual table of "users" called "sites" ?
(2) what database tables do I need to run this example?
Table ("users")
id
site
Table ("files")
id
web_path
system_path
filename
filesize
(3) what is this linking?
I understand what
users.id
is but I don't understand whatusers_files.user_id
is for, its the first time its referenced in this example. Not sure what this is supposed to be...(4) same question for this one. what is this linking?
I understand what
files.id
is but I don't understand the purpose ofusers_files.user_id
No, it makes use of an actual take called
sites
. That isn't actually part of the file upload though. It is a left joined field with a list of options for the user to pick from. See the let him documentation for more information about that.That code would use
user's
,sites
,files
andusers_files
.The SQL for our demos is available in the manual here.
It uses a link / junction table as described in the Mjoin documentation. If you consider the image in the docs there,
users_files
is the link table (also known as a junction table), and the two link statements define how it connects to the two host tables.Allan
Seeing the table creation here is helping to fill out some of the questions in my mind in figuring out how upload works. multiple questions are answered by having a look at this;
https://editor.datatables.net/examples/sql/sqlserver.sql
so by my reckoning
sites
seems to be related to a data function that can be eliminated for purpose of making a simpler multi upload test. One less table to worry about getting correct.What do you think about this controller?
Looks good on a first pass scan. Have you tried running it? What happens?
Allan
my first attempt at adding upload to my existing code was unsuccessful. On drawing the table i get an error in visual studio "{An item with the same key has already been added.}"
Sooo... for my learning purposes i need to back this up a step and build off a known working example.
I started with a stock controller from editor generator.
and turned it into this
Well... Im stil having troubles. Im stuck and dont know what to troubleshoot as I am still not 100% certain what upload needs to function.
I started with a known working example
then I add the upload items
and I get this when the table attempts to draw
I don't understand what I need to do next...
Hi,
The error message indicates what the issue is (I had to keep the error message succinct so maybe it doesn't explain the issue fully). It points to this line as being the issue, since it is where
Flex_OnCall_3Model.TableID
is referenced:Try adding:
to the Editor initialisation (i.e. between lines 2 and 3 in the code above).
That said, it should see that
TableID
is the primary key, so it looks like there is something wrong there. Apologies. Hopefully this will work around the issue for the moment for you.Allan
Perfect! I now have a working example drawing the table. Now I can use that as as a basis for integrating upload into existing code.
Thank you Allan!
I am testing upload and when I attempt to upload a file I get this error message. I'm not certain what this message is trying to tell me.
File upload requires that 'Process' be called with an HttpRequest or UnvalidatedRequestValues object
Could you try:
please? I think that should do it.
Allan
I think it needs to be .Process(request)
here is what happens when I change it to .Process(Request)
here is my original ` var request = '
I think I've spotted the issue, and it is due to the way Generator is creating the code. It doesn't have a file upload ability, and I've never tried to add upload to a Generator package before myself, so i didn't catch this - apologies.
The issue is:
ApiController
extends fromHttpRequestMessage
which does not have file information. What to do is change that line to be:And use the
.Process(Request)
that I suggested.That should do the trick (apologies - don't have a Windows computed here with me to check at the moment). Assuming that does the business, I'll get Generator updated for that.
Allan
Getting closer to this working...
Now I get this error message.
I think my path to the controller is wrong.
The paths i tried is;
APData
and
/APData
Use the troubleshooting steps found at the link in the error:
https://datatables.net/manual/tech-notes/7
You might need to look at your webserver's log for details. If its a path issue you will need to look at your webserver's config to find the correct path.
Let us know what you find.
Kevin
/APData
should be right based on that.Allan
I now have the form ajax properly hitting the controller.
Now onto the next issue.
I am getting this issue on the JSON return.
I could be mistaken but I believe this issue popped up when I switched the controller from:
to
and... Im back to my old tricks of answering my own question.
The solution was to change
IHttpActionResult
toActionResult
We have re-arrived at my May 12th issue.
When I upload an image, I get this error.
File upload requires that 'Process' be called with an HttpRequest or UnvalidatedRequestValues object
Don't know what to try next...
Can you show me the latest full controller code please? The
Request
object inside aController
method is aHttpRequest
.Thanks,
Allan
Would it be ok if I send you the controller in a PM?
Absolutely! Click my user name and then the "Send message" button.
Allan
My system path for localhost testing is very different than the system path on the production server. (although the web path is identical for both). Is there an easy way to code in two different paths that will switch depending on testing vs production?
additional info on above post.
For example on localhost;
{"system_path", Upload.DbType.SystemPath},
thinks the local system path isC:\Program Files (x86)\IIS Express\wwwroot\uploads\
when the actually the localhost, local system path is...
D:\Users\dp\Dropbox\Code\AppSheet\AppSheetData\uploads
You could use an environment variable, which is what I do. That's outside the scope of what Editor provides though, and is a general concept in .NET.
Allan
10-4 ill do the localhost trickery upstream of upload.
And... I'm up and running on localhost now for a line of testing...
Thank you Allan for all of your assistance.