Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#14768 closed defect (fixed)

dojox/form/Uploader doesn't support content negotiation

Reported by: mikeb Owned by: Mike Wilcox
Priority: undecided Milestone: 1.9
Component: DojoX Uploader Version: 1.7.1
Keywords: Cc:
Blocked By: Blocking:

Description

The Uploader should support content negotiation by setting the Accept header on the POST. If the server to which we upload a file accepts both text/html (as required by IE) and application/json (for the other browsers), then the API that produces text/html will always be used because the HTML5 plugin does not use the accept header.

A simple fix is adding the line: xhr.setRequestHeader("Accept","application/json"); around line 173, right after the xhr.open()

A better solution might be to add getters/setters for the XHR object in the plugin so people can customize the headers they want to send.

Change History (9)

comment:1 Changed 7 years ago by Tom Trenka

Owner: changed from dante to Mike Wilcox
Status: newassigned

comment:2 Changed 7 years ago by bill

Component: DojoX FormDojoX Uploader

comment:3 Changed 7 years ago by Karl Tiedt

Just ran into this same problem, looking at some solutions, is Mike Wilcox still supporting this widget in any fashion?

comment:4 Changed 7 years ago by Mike Wilcox

Mike Wilcox is alive but currently does not have time to support this widget. But he is available to apply patches or consult on potential changes.

comment:5 Changed 7 years ago by Karl Tiedt

Thanks for the quick reply Mike Wilcox, Karl Tiedt will be in touch with some patches in the near future if you don't mind a quick review ;)

comment:6 Changed 6 years ago by hndykstra

Is this active? I was having similar problem (dojo 1.8.6) and I patched the uploader plugins as follows:

HTML5: add acceptType: 'application/json' to the declaration. This is the type of the returned text that the HTML5 uploader expects. In createXhr I added if (this.acceptType) { xhr.setRequestHeader("Accepts", this.acceptType); } right after the xhr.open.

IFrame: whenever the IFrame plugin sets this.uploadType = 'iframe' it also sets this.acceptType = 'text/html'. This is the <textarea>...</textarea> structure it expects.

Flash: whenever the Flash plugin sets this.uploadType = 'flash' it also sets this.acceptType = 'text/plan'. This seems to be what the swf handles.

The net effect is that the Accepts header should be set in the Ajax POST request according to the plugin that is being used. This is cleaner for my application (using Jersey) to map the request to a handler that understands it.

It seems to work for me in Chrome (for the HTML5) and IE8/9 (for the IFrame). But I haven't really tested it very broadly - just on those browsers and only for a single selectionMode file uploader. (And nothing at all for the Flash.)

comment:7 Changed 6 years ago by Mike Wilcox

Resolution: fixed
Status: assignedclosed

I added the simple suggestion of adding the header. This isn't strictly tested other than it doesn't cause problems.

comment:8 Changed 6 years ago by bill

For the record: (In [30328]) Fixes: #14768, #15151, #16293, #14914, #14811, #11885, #14075 converted Uploader to use AMD properly which required discarding the plugin approach. All functionality is now included in Uploader. plugins remain for backcompat in order to throw warnings.

comment:9 Changed 6 years ago by bill

Milestone: tbd1.9
Note: See TracTickets for help on using tickets.