vsivsi / meteor-file-collection

Extends Meteor Collections to handle file data using MongoDB gridFS.
http://atmospherejs.com/vsivsi/file-collection
Other
159 stars 37 forks source link

how can we set Resumable's header ? #130

Closed crapthings closed 8 years ago

crapthings commented 8 years ago

i've set these code before resumable.upload(), but there's nothing in req.headers

Documents.resumable.defaults.headers = { 'x-auth-token': Accounts._storedLoginToken() }

Documents.resumable.withCredentials = true

vsivsi commented 8 years ago

To customize resumable, you need to create your own resumable instance, rather than using the one automatically provided on the client.

It's easy, just use the code for the default implementation as a reference: https://github.com/vsivsi/meteor-file-collection/blob/master/src/resumable_client.coffee#L28-L46

crapthings commented 8 years ago

i can find key, but there's no value found in req.headers

'access-control-request-headers': 'origin, content-type, x-cube-token, x-auth-token',

it's working on desktop browser

not work with cordova preflight request, like above only key that i can find in 'access-control-request-headers'

crapthings commented 8 years ago

after add "a custom key string" to preflight options

'Access-Control-Allow-Headers': 'x-auth-token, user-agent, x-cube-token',

it works

but the if i remove x-cube-token(a custom header)

i can't get x-auth-token too, its weird

'Access-Control-Allow-Headers': 'x-auth-token, user-agent',

failed to get x-auth-token from cordova

crapthings commented 8 years ago

now everything works fine!!!

fengyibo commented 7 years ago

@crapthings your reply is so helpfull, could you tell me how to make that works fine. we handle auth with cordova but handle_auth always return null

`handle_auth = (req, res, next) -> unless req.meteorUserId?

Lookup userId if token is provided in HTTP heder

     if req.headers?['x-auth-token']?
        req.meteorUserId = lookup_userId_by_token req.headers['x-auth-token']
     # Or as a URL query of the same name
     else if req.cookies?['X-Auth-Token']?
        req.meteorUserId = lookup_userId_by_token req.cookies['X-Auth-Token']
     else
        req.meteorUserId = null`
crapthings commented 7 years ago

等我有电脑的

fengyibo commented 7 years ago

@crapthings 谢谢啊,路过济南或者上海我请客 有想在济南做meteor开发的小伙伴欢迎推荐

fengyibo commented 7 years ago

@crapthings

Documents.resumable.defaults.headers = { 'x-auth-token': Accounts._storedLoginToken() } 'Access-Control-Allow-Headers': 'x-auth-token, user-agent', http post 方法可以正常获取 x-auth-token,cordova 下http options 还是取不到 x-auth-token,貌似resumable.defaults.headers 没有影响到 options 方法,或者是因为options方法是由浏览器触发的,所以使用的不是 resumable的header??? 求教!

crapthings commented 7 years ago

Documents.resumable

这下边有个叫 opt还是opts 的对象,实际在这里写

Documents.resumable.opt.headers = { test: 1 }

后边就能抓到了

fengyibo commented 7 years ago

用了opts的设置,post 时可以抓到,options还是不行,估计是因为options是浏览器触发的原因吧

crapthings commented 7 years ago

@fengyibo

https://github.com/crapthings/meteor-cordova-file-upload/blob/master/lib/files.js

https://github.com/crapthings/meteor-cordova-file-upload