ivan-novakov / extjs-upload-widget

File upload widget for ExtJS v4
81 stars 42 forks source link

File sync uses to 'PUT' method instead of 'POST' in latest version? #18

Open hhandoko opened 10 years ago

hhandoko commented 10 years ago

I've updated the widget to the latest version (the most recent 'master' commit), but I noticed that the store sync method (when 'Upload' button is clicked) uses 'PUT' which causes the method to fail / behave erratically (e.g. web server may respond with a 500 or a 405, or just fail silently).

Unfortunately I can't seem to locate the particular change in the source (through comparing the latest version that I have vs the latest version).

ivan-novakov commented 10 years ago

I'm not sure I get this - your problem is that the widget uses the PUT method and the server doesn't support it? I think that the PUT method was default before the update also. Anyway, it is possible to set alternative method like POST.

I'm not sure which method should be default. The difference between POST and PUT is IMHO in immutability - PUT is immutable, POST is not.

hhandoko commented 10 years ago

That's strange, I haven't done any special configuration using the previous version, and it defaults to POST. The reason I noticed, is that after upgrading, the server started returning 404's as I haven't defined a PUT endpoint. I've updated the server-side methods to PUT but the behaviour is erratic.

How would I set the default method to POST? Do I need to specify the uploader specifically and pass on the options?

Here's what I have currently.

var dialog = Ext.create('Ext.ux.upload.Dialog', {
    dialogTitle: 'File Upload',
    uploadUrl: Ext.String.format('shipments/{0}/attachments', shipmentCode)
});

if (!dialog.hasListener('beforeclose')) {
    dialog.addListener('beforeclose', this.load);
}

dialog.show();

PS: At the moment I use POST for create and PUT for update operations. But, thanks for the tip about POST vs PUT, there's certainly a lot of differing opinion about REST verb usages and I'll need to do a bit more research.