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

Adding the ability to specify headers for a URL based attachment #498

Open
brendon opened this issue Nov 30, 2018 · 3 comments · May be fixed by #499
Open

Adding the ability to specify headers for a URL based attachment #498

brendon opened this issue Nov 30, 2018 · 3 comments · May be fixed by #499

Comments

@brendon
Copy link

brendon commented Nov 30, 2018

Hi @markevans, I hope all is going well in the leadup to Christmas :)

I'm looking to download files from Google Drive via dragonfly. They'll be specified by the user using the Google Drive file picker tool that returns a file_id and oauth_token. I can send these back to the server and have Dragonfly download the file from there. The trouble is that to download the file, the oauth token needs to be specified in a header:

GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization: Bearer <ACCESS_TOKEN>

See: https://developers.google.com/drive/api/v3/manage-downloads

I've had a look at the code and it appears specifying extra headers isn't currently supported. Would you be interested in having this as a feature? or do you think there's another way to do this?

I guess the biggest challenge would be working out a tidy way to pass in the extra headers. Perhaps passing a hash to the assignment method that contains say:

@photo.image_url = {
  url: 'https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media',
  headers: { 'Authorization': 'Bearer <ACCESS_TOKEN>' }
}

would work? I'd be keen to get onto this asap, so if you had any ideas or pointers before I begin that would be really helpful :)

@markevans
Copy link
Owner

hi - I'd be reluctant to change anything with the model.image_url= method as this is just a convenience method that will get complicated if adding extra stuff. The place to do it would be in fetch_url. You could do

photo.image = Dragonfly.app.fetch_url("https://www.goo...", headers: {"Authorization"=> "Bearer <TOKEN>"})

The only thing missing that isn't currently implemented is the second arg with headers: {... in FetchUrl, but it would be fairly easy to add.

@brendon brendon linked a pull request Dec 2, 2018 that will close this issue
@brendon
Copy link
Author

brendon commented Dec 2, 2018

Thanks @markevans, that makes a lot of sense. I've created a PR for this. Fairly simple. Let me know if there's anything to fix :)

@brendon
Copy link
Author

brendon commented Dec 3, 2018

I've tested this approach in my app now and it works well.

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

Successfully merging a pull request may close this issue.

2 participants