Using FineUploader 3.8.2 to upload PDF files to S3, I am running into an interesting issue and not sure if perhaps I'm just using the wrong syntax or not understanding how the options should work for fineUploader. Here is my code...
var uploader = $('#fine-uploader-box').fineUploaderS3({
debug: true,
button: $('#choose-file-button'),
multiple: false,
autoUpload: false,
request: {
endpoint: '(no url yet because I need to know about the file before I can construct an S3 PUT url)'
},
callbacks: {
onSubmit: function(id, name){ // function to get real endpoint url goes here },
onSubmitted: function(id, name){ // or function to get real endpoint url goes here }
},
validation: {
allowedExtensions: ['pdf']
}
});
What I am trying to do is just get a function to run once my file has been added to the list but I am not seeing the onSubmit (or onSubmitted) firing.
My goal is to have that function do some ajax-y stuff and return some information in which I will use to facilitate the rest of the upload process including getting a specialized S3 PUT url from my server to send my upload to.
Any help would be greatly appreciated. Thanks.
It appears that you are using the syntax for the non-jQuery uploader, but you are using the jQuery uploader. Check out the below:
var uploader = $('#fine-uploader-box').fineUploaderS3({
debug: true,
button: $('#choose-file-button'),
multiple: false,
autoUpload: false,
request: {
endpoint: '(no url yet because I need to know about the file before I can construct an S3 PUT url)'
},
validation: {
allowedExtensions: ['pdf']
}
}).on('submit', function (event, fileId, fileName) {
alert("File id: "+fileId);
}).on('submitted', function (event, fileId, fileName) {
alert("File id: "+fileId);
});
Related
I want to use DataTables Editor but I want full control over the post back rather than letting Editor-Server handle it. Is there a way to do this? I am able to specifiy the url in Ajax on the client side and it does post back to the Controller, the only problem is I cannot figure how to get the data out of the call.
This is the Ajax portion:
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: ({
url: "/../AnyController/Update",
dataType: "json",
contentType: "application/json",
type: 'POST'
}),
formOptions: {
inline: {
onBlur: true,
submit: 'all'
}
},
table: "#timetracker",
fields: [
{
label: "Date1:",
name: "Date1"
},
{
label: "Comment 1:",
name: "Comment1",
type: "textarea"
}
]
});
And this is the Contoller method:
[HttpPost]
public JsonResult Update(EditorReturnData wtd)
{
return Json(wtd);
}
I have tried using a variety of other method signatures but the value of wtd is always null. I have no problem loading the table just by passing Json data, but how to takeover the update process from datatables editor is eluding me.
I have one update. I could not figure out how the Get, Post and Put could all use the same Controller Method and the method takes no parameters, even for the Post and Put. Finally I figured out that Editor is passing the data in the Header and it could be accessed with Request.Body. From there it must be the Datatables dll that is doing the actual updates.
enter code hereI have found the best way to do this is to post back from ajax to a different Controller for Post and Put and you can get access to the return data from the HttpRequest body in the following manner.
public ActionResult Rest(HttpRequest request)
{
var stream = request.Body;
string url = new StreamReader(stream).ReadToEnd();
string newUrl;
while ((newUrl = Uri.UnescapeDataString(url)) != url)
url = newUrl;
I added this code to the RestController from the Datatables Dot Net Core Demo Rest example which can be downloaded from https://editor.datatables.net/
The Ajax looks like this
editor = new $.fn.dataTable.Editor( {
ajax: {
create: {
type: 'POST',
url: '/api/rest/create'
},
edit: {
type: 'PUT',
url: '/api/rest/edit'
},
remove: {
type: 'DELETE',
url: '/api/rest/remove'
}
},
I am opening an kendo window using the below jquery function.
I need to pass __RequestVerificationToken to the MVC Controller because I am having ValidateAntiForgeryToken Attribute.
However, I am not able to pass it. Can you please suggest how to pass __RequestVerificationToken while opening an kendoWindow
function OpenTest() {
var url = '#Url.ActionWithArea("OpenTest", "Test", GlobalConst.AREA_Test)';
url += "?test=" +$("#test").val() +
"&test1=" +$("#test1").val();
windowElement = $('<div id = "abc" />').kendoWindow({
title: 'test',
content: url,
modal: true,
resizable: false,
draggable: false,
width: 900,
height: 400,
close: function () { windowElement.destroy(); }).data("kendoWindow").center().open();
return false;
}
You might want to think about including this token at a more global scope in your application so you don't have to meddle with it on a per call basis.
There is an example over on the Kendo UI forums, about halfway down. The data signature of your route should look like:
transport: {
read: {
url: url,
type: "POST",
data: {__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
}
}
Or in your case, something like this -->
'#Url.ActionWithArea("OpenTest", "Test", new { __RequestVerificationToken=<value> }),GlobalConst.AREA_Test)';
$("#imgBrowser").kendoEditor({
tools: [
"insertImage"
],
imageBrowser: {
messages: {
dropFilesHere: "Drop files here"
},
transport: {
read: "/ImageBrowser/Read",
destroy: {
url: "/ImageBrowser/Destroy",
type: "POST"
},
create: {
url: "/ImageBrowser/Create",
type: "POST"
},
thumbnailUrl: "/ImageBrowser/Thumbnail",
uploadUrl: "/ImageBrowser/Upload",
imageUrl: "~/ImageGallery//Image?path={0}"
},
change: function () {
//this.value(); //Selected image URL
},
select: function () {
}
}, execute: function (e) {
},
change: function () {
},
select: function () {
}
});
I am new to kendo Controls. i want to save images in my project folder. I am Using this code but it is not calling Controller Actions but when i am uploading image it is giving. images re also not saving in folder it is showing always loading icon. when i upload any image it is showing this below error.
Error! Requested Url returned 405 - method not allowed
Please help me how can i resolve this error. and how can i save uploaded images into my project folder.
You should change your application web.config, This link help you through the way
http://www.asp.net/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications
I am trying to get a grid filled with the json response I would receive when making a httpwebrequest call to a url endpoint which requires authentication. The data will be in json form:
{
"data": [
{
"value": "(\"Samsung Health\")",
"tag": "ME"
},
{
"value": "(\"Samsung Galaxy Tab\")",
"tag": "HIM"
},
{
"value": "(\"Amazon fire\")",
"tag": "ME"
}
]
}
I am not sure how to even start and whether to use Ext.Ajax.Request or some type of call from code behind. I am using vb.net in code behind. Any suggestions appreciated. Sample code for ajax call;
function getMembers() {
var parameters = {
node: dynamicNodeId
}
Ext.Ajax.Request({
url: 'https://data.json',
method: 'GET',
jsonData: Ext.encode(parameters),
success: function (response, opts) {
alert('I WORKED!');
//decode json string
var responseData = Ext.decode(response.responseText);
//Load store from here
memberStore.loadData(responseData);
},
failure: function (response, opts) {
alert('I DID NOT WORK!');
}
});
}
The grid formation:
var grid = Ext.create('Ext.grid.Panel', {
store: store,
stateful: true,
stateId: 'stateGrid',
columns: [
{
text: 'Query',
flex: 1,
sortable: false,
dataIndex: 'query'
},
{
text: 'Last Updated',
width: 85,
sortable: true,
renderer: Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex: 'lastChange'
},
Here query would be the value from the json response and lastChange the current datetime. I tried the proxy request call and realized that since I am calling an endpoint on a different domain I needed to use jsonp.
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'jsonp',
extraParams: {
login: 'username',
password: 'password'
},
url: 'https://api.data/rules.json',
reader: {
type: 'json',
root: 'rules'
},
callbackParam: 'callback'
},
autoLoad: true
});
I might have to just figure out some other way to do by making sure all the data I needed is called to a database by some other function.
The best approach for your situation would be to create store that is configured with a remote proxy. See the example at the top of this documentation page: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store
The remote proxy will take care of the AJAX request to retrieve the data, and the store will automatically manage casting the data results to Ext.data.Model instances. Once the store is loaded with data, the grid to which the store is bound will also automatically handle rendering the data that has been populated into the store.
From my extended Ext.data.TreeStore:
proxy: {
type: 'ajax',
api: {
read: "/GetTree.json",
update: "/SetTree.aspx?username=user1"
},
reader: {
type: 'json',
root: 'children'
},
listeners: {
exception: function (proxy, response, options) {
// error case
console.log('Exception in Portlets store proxy...');
console.log(response);
}
}
},
What I am trying to figure out is how can I make the username=user1 dynamic, such that I could pass in user2 and have the aspx page process with that user data.
I cannot figure out if/how TreeStore.sync() allows parameters to be passed into it.
Update:
What I am really after here is the ability to save back the entire tree structure as a JSON string instead of just the record that was updated. I can build the JSON string I need to pass but cannot figure out how to actually get that information to my SetTree.aspx page.
You can try setting extra params on the proxy before calling sync:
store.proxy.extraParams = { param1 : '', param2 : '' };
There is anecdotal evidence that suggests this works in 4.1.3 but not earlier versions.
Another thought is to just fire a regular Ajax.request and send desired params along instead of using the tree store to do that.
I know this is old, but for people like me that were searching for the same question...
If you want to save the entire structure instead of just the modified lines, you need to define a writer in your store proxy and in that writer, set writeAllFields: false:
proxy: {
type: 'ajax',
api: {
read: "/GetTree.json",
update: "/SetTree.aspx?username=user1"
},
reader: {
type: 'json',
root: 'children'
},
listeners: {
exception: function (proxy, response, options) {
// error case
console.log('Exception in Portlets store proxy...');
console.log(response);
}
},
writer: {
type: 'json',
writeAllFields: true
}
},