Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept request header always set to 'text/*' when reverting to FileApi #121

Closed
mbyrne00 opened this issue Jan 31, 2014 · 5 comments
Closed

Comments

@mbyrne00
Copy link

When using the plugin with a HTML5 compatible browser it produces a request with the Accept request header as 'application/json', however the FileApi (flash) code always produces an Accept header of 'text/*'.

I can't find a way to override this and this causes issues with Java server-side code.

Any workarounds in the mean time would be greatly appreciated.

The following have been tried and have no effect:

  1. Setting headers in $upload:
    $upload.upload({headers: {accept:'application/json',....}})

  2. Editing angular-file-upload-shim.js and forcing header config
    // Hack to try to force headers to be passed to FileAPI
    config.headers = {'Accept': 'application/json'};
    // Existing line below
    xhr.__fileApiXHR = FileAPI.upload(config);

After making each of the above changes and sniffing the traffic, the Accept header was still 'text/*'

@danialfarid
Copy link
Owner

Add below lines here https://github.com/danialfarid/angular-file-upload/blob/master/dist/angular-file-upload-shim.js#L113

FileAPI.accept = 'application/json';
config.accept = 'application/json';

If that works I do a fix release tomorrow.

@mbyrne00
Copy link
Author

Hey Danial - thanks a lot for the quick response but all my code is at work and I'm home for the weekend now so won't be able to try again until Monday (Australian timezone).

I will definitely give it a go and feedback although I did a bit of searching on the train ride home and after looking at the flash API http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#upload() and other comments on FileAPI https://github.com/mailru/FileAPI/issues/59 I don't hold out much hope. I think the Flash API itself is too inflexible to allow it.

I'll let you know how I get on after the weekend.

@danialfarid
Copy link
Owner

Yea you are right it doesn't work.
We gotta wait for FileAPI new release to see if it fixes it or not. https://github.com/mailru/FileAPI/issues/189#issuecomment-33807468

@mbyrne00
Copy link
Author

mbyrne00 commented Feb 2, 2014

Hmm ok - looks like you have proven it won't work :-(

I'll look at fudging the backend to allow 'text/*' for JSON.

Thanks for checking this out though!

@danialfarid
Copy link
Owner

No easy solution or alternative for this and there are server workarounds for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants