An error occured on upload
An error occured on upload
I have the same issue as this post below. The file is saved to the database and all but I keep hitting an error when trying to return the right Json to editor.
https://datatables.net/forums/discussion/comment/225563/#Comment_225563
This is my return. I am using c# and I have tried using return Json(), returning it as a string, and JsonSerializer:
{
"files": {
"fileId": 1
}
}
This question has an accepted answers - jump to answer
Answers
Hi,
Have you taken a look at the Ajax request in the browser's network inspector? That might give a clue as to what is going wrong.
Can you give me a link to the page so I can take a look? You can PM it to me if you don't want to make it public
.
Allan
Hey Allan, unfortunately I can't. The application is not external. I have change the response json multiple times. Currently, this is what I have:
{
"files": {
"file": {
"fileId": 12,
"fileName": "CallEndpointwAuthHeader.PNG",
"webPath": "/ProjectInfo/Download/630"
}
}
}
My editor javascript code for the upload looks like this:
The documentation is pretty vague on this particular topic. Can you help me figure this out?
By the way, I am not saving the file to the file system. I am using MemoryStream to save it directly to the database. Do I need to save it to the file system for this to work properly?
The response should look something like this:
The documentation for it is available here.
The key part is the
upload.id
property, which Editor will look for to know what the primary key identifier for the file is. That is currently missing from your response. You also need to nest the file information in an object with the primary key's value - so your response might look something like:Allan
Hey Allan, the information you've given me has been extremely helpful and I am able to make the upload work, just not in a way that would be useful. I think the way I think it should work is not the way it is designed, so I will have to build my own file upload process. What I expect is:
This workflow doesn't seem possible with Editor in its current form. Would you agree? Or am I missing something?
Hi,
Yes you are right - the way the file upload works for Editor is to send an Async request to the server to upload the file, so it might be present before the host row has been created. If that row is never created, then the file is considered to be "orphaned". The provided libraries have a method for help to handle this, which also covers row deletion as well.
This method works well for cases where the file is a foreign key reference in the host table (i.e. a left join to a
files
table). It isn't so useful if you want to store the file in the host table.Adding synchronous upload is something that I am considering for a future version, unfortunately it is not a feature of Editor at this time, but I can look more into it.
Allan
Some users want to upload many files, mostly an entire folder. I tell them to zip it and upload the zip file. Done. I guess this would also deal with @heizler 's use case.
Advantages:
The data table display isn't polluted with dozens of files displayed but just one zip file.
Simple upload.
Oh that definitely makes sense but is a bit more involved than our simple case. We only have the host table and are only uploading 1 or 2 documents for project documentation. If you get around to adding the synchronous version in the future definitely keep the existing version and potentially provide an option for synchronous vs asynchronous
Absolutely! The default wouldn't change - very likely it would be an
async
option in theupload
configuration object. It would change the Editor form submission, but that can be taken account of. I try to make sure changes are backwards compatibleAre you sorting the files in the db, or in the file system?
Allan