jesus / dropbox_api Goto Github PK
View Code? Open in Web Editor NEWRuby client library for Dropbox API v2
License: MIT License
Ruby client library for Dropbox API v2
License: MIT License
Hi, I have this warning -> WARNING: Faraday::Connection#authorization
is deprecated; it will be removed in version 2.0.
While initializing your connection, use #request(:authorization, ...)
instead.
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
I've been experimenting with the upload session API, and I think I've found a bug not covered by the current test cases.
commit = DropboxApi::Metadata::CommitInfo.new({
"path" => "/test.txt",
"mode" => :add
})
# Upload the first three bytes
cursor = client.upload_session_start('abc')
# Cursor offset has been correctly set to 3 at this point
expect(cursor.offset).to eq(3)
# Upload the second three bytes
client.upload_session_append_v2(cursor, 'def')
# Cursor offset *should* be set to 6 at this point, but remains 3
# expect(cursor.offset).to eq(6)
# Attempt to commit the upload
client.upload_session_finish(cursor, commit)
This raises an error:
DropboxApi::Errors::UploadSessionOffsetError:
lookup_failed/incorrect_offset/..., correct offset: 6
This happens because the offset of the cursor never changes from 3 to 6 after the call to upload_session_append_v2
.
This hack will cause the test to pass:
cursor = client.upload_session_start('abc')
client.upload_session_append_v2(cursor, 'def')
# Manually update the offset
cursor.instance_variable_set(:@offset, 6)
client.upload_session_finish(cursor, commit)
There are test cases covering upload_session_append_v2
and upload_session_finish
, but never the two together, which would otherwise reveal this problem.
I believe the correct behaviour is to have upload_session_append_v2
update the cursors offset after a successful request, and I'm working on a fix for this at the moment – let me know if you have any thoughts on this in the meantime.
Hi, is there any way to download online file in Dropbox. The URL includes dl=0.
This file is a shared remote file. But I had no luck to download.
Anyone can help me?
when downloading file, metadata of file object was generated but file content not generated ,
I searched methods on the file metadata object but i can't succed.
dropbox_api gemspec has a dependency on 'faraday', '~> 1.0'
.
Faraday 2.0.0 was released on Jan 4 2021.
An app using dropbox_api (or anything that depends on it) can't upgrade to faraday 2.0 unless/until dropbox_api's specification is relaxed.
Could dropbox_api be verified and released for faraday 2.0?
https://github.com/lostisland/faraday/blob/main/UPGRADING.md
I'm using this gem to get a link to a folder in my Dropbox, but when I perform the following operation, I get an error.
link = @client.get_temporary_link(item_path)
Here's the error.
/Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/endpoints/base.rb:36:in `process_response': HTTP 400: Error in call to API function "files/get_temporary_link": request body: path: 'None' expected to be a string, got null (DropboxApi::Errors::HttpError)
from /Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/endpoints/base.rb:11:in `perform_request'
from /Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/endpoints/files/get_temporary_link.rb:14:in `block in <class:GetTemporaryLink>'
from /Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/cli
The same happened with other functions, such as create_shared_link_with_settings
.
What am I missing?
API issue
When trying to client = DropboxApi::Client.new(access_token: "xxxx")
just not working, having response raise ArgumentError, "access_token should be an OAuth2::AccessToken"
Hi!
I was looking through the code to see how the authentication with Oauth2 was implemented, and found that you were using the v1 endpoints instead of v2: https://github.com/Jesus/dropbox_api/blob/master/lib/dropbox_api/authenticator.rb#L9-L10
The change should be simple though, according to https://www.dropbox.com/developers/reference/migration-guide you only need to drop the /1
in the urls.
Was this left with the v1 endpoints for a reason?
upload_by_chunks
It looks like there's currently no ability to revoke a token once a user has completed the OAuth flow. I can look into adding it if that's something you'd accept in a PR.
I've been searching through the docs and before I dive into the gem source code itself any further I would like to know the following: is it possible to generate a link to a dropbox folder with your gem?
I am building a string from DropboxApi::Metadata::Folder#path_lower
, which indeed returns the url path for the folder. However, the path is missing /home
, which seems to be the root of all created dropbox folders. To actually generate a url to the folder, I have to do something that I do not love:
"https://dropbox.com/home#{DropboxAPI::Client.new('/some/path/to/folder/').get_metadata('/some/path/to/folder/').path_lower}"
# => https://dropbox.com/home/some/path/to/folder/
I was testing uploading via sessions and found that I got an offset error when trying to upload binary files. I believe I tracked it down to upload_session_start.rb line 34, where
"offset" => content.size
I believe that this should be
"offset" => content.bytesize
size returns the character length, whereas bytesize returns the length of the string in bytes. These sizes may not be the same if the file is not pure text.
I was able to create a new cursor with the content.bytesize and pass it to upload_session_finish and the file transferred properly.
Thanks for your work on this API. It's been a big timesaver.
I may be posting this issue prematurely but all of a sudden my client is getting this error when using the search
function. Nothing has changed on our end. Perhaps Dropbox just now made a change to their way their search endpoint works?
EDIT: Apparently I have discovered the error returned when Dropbox returns an undocumented match_type. There's an open PR for fixing this.
In the last step of Oauth2 when I use:
dropbox_authenticator.get_token(params[:code])
I'm getting the error from the title. I'm using http://localhost:3000 for now.
Any help would be greatly appreciated.
First off, thanks for all the hard work. This gem has helped me out a ton!
I'll be adding the upload_session_*
functionality soon and was wondering if you have any ideas about the best way to handle bigger files. Do you have any examples?
Do you think determining whether the file needs to be uploaded normally or chunked seems like functionality this gem could handle automatically in the future?
Thanks for creating a Ruby SDK. You'll notice that our other official SDKs use a library called Stone to generate routes and data types, which makes keeping up-to-date with all our API changes easier as we regularly update our specs repo. Unfortunately, we don't have a Ruby generator, but this is a light tap that we would be delighted if a 3rd party made one :)
I noticed that when the #upload
method is given a string (like the result of IO.read
), the uploaded file is not the correct size.
result1 = service.upload('/test1.png', IO.read('/tmp/test.png'))
result1.size
=> 6208
File.open('/tmp/test.png') do |file|
result2 = service.upload('/test2.png', file)
end
result2.size
=> 6477
File.size('/tmp/test.png')
=> 6477
I compared the content of the two files and they are identical up until test1's premature end (it is missing the last 269 bytes).
I traced the issue to here. I believe the first priority method to call should be #bytesize
, which will get the proper size in bytes. I'd be happy to submit a PR if you agree.
Hello, I wasn't able to upload any file getting this exception.
ArgumentError: Content-Length not given and Transfer-Encoding is not `chunked'
from /home/retro/.rubies/ruby-2.2.6/lib/ruby/2.2.0/net/http/generic_request.rb:192:in `send_request_with_body_stream'
After a little lookup, I was able to fix this by changing build_request
in ContentUpload
.
When I passed one of 'Content-Length' => content.size
or 'Transfer-Encoding' => 'chunked'
as an additional header, everything worked as expected and file was uploaded without problems (verified by downloading and md5 hashing).
Does it make sense to include one of these headers by default or at least add new option for upload
method?
I can submit PR once this will be decided.
Thanks for this awesome gem!
I'm having timeout issues when fetching a folder. I can use the dropbox api explorer and curl and all works fine, but as soon as I try in ruby it times out.
Any help would be greatly appreciated.
The lib currently throws a DropboxApi::Errors::HttpError
with response code and response body as a string. There's no way to catch specific http error codes.
dropbox_api requires oauth1
gem 1.x
dropbox_api/dropbox_api.gemspec
Line 24 in 11bd1cf
However, oauth
gem now has a 2.0 release as of June 2022. https://rubygems.org/gems/oauth2/versions/2.0.0
Instalilng the last oauth2 1.x release produces this warning:
You have installed oauth2 version 1.4.11, which is EOL.
No further support is anticipated for the 1.4.x series.
OAuth2 version 2 is released.
There are BREAKING changes, but most will not encounter them, and upgrading should be easy!
We have made two other major migrations:
1. master branch renamed to main
2. Github has been replaced with Gitlab
Please see:
• https://gitlab.com/oauth-xx/oauth2#what-is-new-for-v20
• https://gitlab.com/oauth-xx/oauth2/-/blob/main/CHANGELOG.md
• https://groups.google.com/g/oauth-ruby/c/QA_dtrXWXaE
Please upgrade, report issues, and support the project! Thanks, |7eter l-|. l3oling
Could dropbox_api be updated to allow use of oath2 2.x, perhaps allowing both 1.x and 2.x?
For getting large files from a user's Dropbox, their API allows you to specify a range of bytes--is this possible in the current dropbox_api
gem's DSL?
https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens
The dropbox api supports refresh tokens.
Therefore, I'd like you to support it in this library.
Hi,
I have recently used Get Shared Links method but is only returning 200 files. In the app folder, I had 2000 files. How can I get all of them?
Kind Regards
Andrew
Hello! Great package. Thank you.
The Dropbox documentation says that is supports the state
param when submitting an authorization url. I don't see support for that in the gem. Did I miss it? Is it supported? If not, please?
https://www.dropbox.com/developers/documentation/http/documentation
i try to make the client exactly as explained inside the docs like this:
access_token = OAuth2::AccessToken.from_hash(authenticator, token_hash)
the Dropbox::Token::Save is just a module that saves the token
client = DropboxApi::Client.new(
access_token: access_token,
on_token_refreshed: lambda { |new_token_hash|
Dropbox::Token::Save.perform(new_token_hash)
}
)
the problem is the client gives me this error:
DropboxApi::Errors::HttpError Exception: HTTP 400: Error in call to API function "files/list_folder": Invalid authorization value in HTTP header "Authorization": "Bearer access_token=\"#<OAuth2::AccessToken:0x00007f72ce27efc8>\", on_token_refreshed=\"#<Proc:0x00007f72cdf7d6d0@(byebug):3 (lambda)>\"". Expecting "Bearer <oauth2-access-token>".
and it doesnt refresh the token and doesnt save it.
and even if i dont send the on_token_refresh the error will be :
DropboxApi::Errors::HttpError Exception: HTTP 400: Error in call to API function "files/list_folder": The given OAuth 2 access token is malformed.
looks like the DropboxApi::Client module is not accepting those correctly.
it'd be amazing if someone could help me thanks
I was testing using byebug on the block lambda, and try to save direct in database... but just not triggering
Hi there,
I get the error message "JSON::GeneratorError: only generation of JSON objects or arrays allowed" after trying to collect account data:
client = DropboxApi::Client.new(DROPBOX_TOKEN)
client.get_current_account
I already tried to switch to a different version of execjs gem without success.
Using ruby 2.1.7 and json_pure 2.1.0 for my Rails application.
Did you see this error behaviour in any context before?
Greetings, Alex
The gemspec currently says:
` spec.add_dependency "faraday", "<= 1.0"
dropbox_api/dropbox_api.gemspec
Line 26 in 4c43dc7
That ends up meaning any faraday version less than or equal to 1.0.0, but no greater.
This means 1.0.0 is allowed, but 1.0.1 released March 29 and containing a few bugfixes is not allowed by dropbox_api
. An app using dropbox_api
can use faraday 1.0.0, but not 1.0.1.
I think this is probably not what you intended? Not sure what you intended? Perhaps < 2.0
, meaning allow any 0.x and any 1.x? I would advocate that, I think?
Here is the commit where you changed gemspec to say <= 1.0
, I'm afraid the commit message doesn't have much guidance. 7107370
It complains that i need a team member id in the header and I don't see a way to inject that into the client right now.
I want to use some of the latest features of ChunkedUploader.
So I want to know next release.
please when will you release the next version?
I'm having the hardest time tracking down a bug in using this library for save_url
and save_url_check_job_status
.
I can't recreate it, but while it's running in background jobs (with sidekiq), save_url_check_job_status
will throw NoMethodError: undefined method '[]' for nil:NilClass
tracing to media_info.rb:22
:
So sometimes when save_url_check_job_status
is called, data['metadata']
is nil. Is this a problem with this library, or could it be that I'm calling it in a strange way?
I'm trying to do a small change to the gem (adding the content_hash property).
For this I need to regenerate the VCR cassettes, but it seems like this requires a base Dropbox state with some files in it (eg: file.txt, file.docx, a "folder" folder, etc). I can't seem to find these test files in the repository. Is it available somewhere?
I have used the dropbox_api 0.1.17
in my fastlane
script.
Recently, my project upgraded fastlane
version to latest that also upgraded faraday
to ~> 0.17
.
It's caused the compatible issues of faraday
.
See the changes. fastlane/fastlane@cf2ac51
I restricted fastlane
version on 2.133.0
that before the commit for now.
I'll appreciate If the project could upgrade faraday's version.
I am making one request to authorize a user and would to save the token hash so that I can build an OAuth2::AccessToken at a later time and upload a file without user authorization. I can create the client but if on_token_refreshed is not called, how do I get the token_hash?
For example, I am calling the following once, but on_token_refreshed doesn't get called so I can't get the token hash. Do I need to construct the token_hash manually?
access_token = authenticator.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
client = DropboxApi::Client.new(
access_token: access_token,
on_token_refreshed: lambda { |new_token_hash|
# token_hash is a serializable Hash, something like this:
# {
# "uid"=>"440",
# "token_type"=>"bearer",
# "scope"=>"account_info.read account_info.write...",
# "account_id"=>"dbid:AABOLtA1rT6rRK4vajKZ...",
# :access_token=>"sl.A5Ez_CBsqJILhDawHlmXSoZEhLZ4nuLFVRs6AJ...",
# :refresh_token=>"iMg4Me_oKYUAAAAAAAAAAapQixCgwfXOxuubCuK_...",
# :expires_at=>1632948328
# }
SomewhereSafe.save(new_token_hash)
}
)
https://dropbox.tech/developers/search-files-using-the-dropbox-api
We’ll be retiring the old v1 search on February 28th, 2021. If you haven’t already, please migrate to the search v2 endpoint at your earliest convenience.
https://github.com/Jesus/dropbox_api/blob/master/lib/dropbox_api/endpoints/files/search.rb#L4
The new version should be:
/2/files/search_v2
I'm looking forward to using this client but it seems not all the allowed parameters can be passed to the methods. In particular I'm looking forward to the autorename
param in the files_move endpoint (https://www.dropbox.com/developers/documentation/http/documentation#files-move).
Maybe we could add a third parameter in this endpoint with an hash that would allow to pass all the non required parameters.
What do you think? Any other approach to allow these other params?
I want to upload files in chunk using /upload_session/* endpoints.
It seems that this has not been implemented as per http://www.rubydoc.info/gems/dropbox_api/file/api_coverage.md ,
but there's a comment "Do not use this to upload a file larger than 150 MB. Instead, create an upload session with #upload_session_start()." in upload.rb which is creating the confusion, BTW I was not able to see the implementation of upload_session_start() so I assume it is not implemented till now.
Am I missing something?
What is the best way to upload a large file? I see the documentation mentions something about uploading over 150MB files, but am unsure how to actually implement it. Since it takes a string, is it possible to actually accept a file stream or something so as not to load a massive file into memory and convert it to a string?
Hi there, I'm planning to use this gem because it seems pretty complete, or at the least, it has all the methods I need to make my own syncing script for a Discord bot I'm making.
I noticed over on the rubydoc for this gem that the documentation for the endpoint methods does not appear for all endpoints. Some, such as CreateFolder, will have their methods appear -- but others like Upload do not!
I searched a little into this and I found eb13f33, a commit where all the # @method
stuff was replaced with a YARD plugin. So I looked at the documentation that rubydoc.info had for v0.1.4 of this gem, and lo-and-behold, all the endpoint documentation was there without error.
I don't know what to make of this, I think it's worth looking into however.
I assume I am missing something.. I upload a file and get a thumbnail (for now, assume its a small jpeg being uploaded):
dropbox = DropboxApi::Client.new(ENV['DROPBOX_ACCESS_TOKEN'])
uploaded_file = dropbox.upload(uploaded_path, uploaded_io.read, autorename: true)
thumb = dropbox.get_thumbnail(uploaded_file.path_lower)
inspecting thumb
gives me the same object as uploaded_file
.. how do I get to the thumbnail?
The options for this endpoint are being ignored, the API supports 4 options:
mode
autorename
client_modified
mute
But none of them are implemented by this library.
Looks like Dropbox may respond with a 429 status code and no body or content type is not JSON during file chunks upload.
In this case gem failed with NoMethodError
Gem version: 0.1.21
Backtrace
NoMethodError: undefined method `[]' for nil:NilClass
from dropbox_api/endpoints/base.rb:47:in `process_response'
from dropbox_api/endpoints/content_upload.rb:23:in `perform_request'
from dropbox_api/endpoints/files/upload_session_start.rb:31:in `block in <class:UploadSessionStart>'
from dropbox_api/client.rb:36:in `block in add_endpoint'
from dropbox_api/chunked_uploader.rb:19:in `start'
from dropbox_api/endpoints/virtual/upload_by_chunks.rb:45:in `upload_by_chunks'
dropbox_api/endpoints/base.rb:47
45 when 429
46 error = DropboxApi::Errors::TooManyRequestsError.build(
47 raw_response.env[:api_result]['error_summary'],
48 raw_response.env[:api_result]['error']['reason']
Hi there, thanks for the awesome job. I have an issue which I am not sure how to do.
client = DropboxApi::Client.new()
object = client.get_temporary_link "/app/path"
#results
#<DropboxApi::Results::GetTemporaryLinkResult:0xsada12312 @data={"metadata"=> .
{"link"=>"http://dl.dropboxusercontent.com...}>
The question is I am not sure how to get the link
from the results... I tried something like object.data['metadata']['link']
but which returns *** NoMethodError Exception: undefined method data
error. What am I doing wrong?
I've written an app that uses the dropbox_api
gem to list and upload files. It works great, but now I need to make it work with the Dropbox Business API.
The Dropbox Business API has a set if its own endpoints, plus a change in request behaviour for the normal Dropbox API endpoint. At this stage, I don't need the additional endpoints, just the altered request behaviour.
The change needed is to add a header – Dropbox-API-Select-User
(or Dropbox-API-Select-Admin
) – which contains a team member ID (this is separate from a user ID). Using this header, I can request any of the standard API endpoints, performing each action on behalf of a user in a team.
There's a couple of approaches I can take to implementing this, and ideally I'd like to submit the work and get it accepted back to this gem, so I'm opening this issue for discussion now before I start work on it. I'd love to hear your thoughts.
One option would be to add a method to the client which would allow you to have access to the ConnectionBuilder
's Faraday connection:
client = DropboxApi::Client.new(...)
client.middleware do |connection|
connection.headers['Dropbox-API-Select-User'] = '...'
end
client.list_folder('/gifs')
This would be my preferred solution, as exposing the middleware would allow a user to arbitrarily add, for example, custom logging or error handling.
def build(url)
Faraday.new(url) do |c|
@middleware_callback.call(c) # <---
c.authorization :Bearer, @oauth_bearer
yield c
c.adapter Faraday.default_adapter
end
end
Given that some endpoints manipulate the headers, this may cause some headaches. There's also the classic problem of Faraday's middleware ordering – the ability to customise the connection will depend on where the callback gets called inside the block.
Another option to solve this problem would be to pass an optional parameter to the connection builder, through the client:
client = DropboxApi::Client.new(token, select_user: '...')
client.list_folder('/gifs')
This would work by passing the select_user
to the ConnectionBuilder
, which would insert it something like this:
def build(url)
Faraday.new(url) do |c|
c.authorization :Bearer, @oauth_bearer
if @team_member_id
c.headers['Dropbox-API-Select-User'] = @select_user
end
yield c
c.adapter Faraday.default_adapter
end
end
This would basically involving patching a bunch of endpoints to allow a select_user
option.
client = DropboxApi::Client.new(token)
client.list_folder('/gifs', select_user: '...')
Hello,
I found an issue when trying to iterate through a publicly shared folder. The Dropbox API documentation instructs to use the shared_link
option of the list_folder
request. The dropbox_api gem (unknowingly, I guess) supports this option:
result = client.list_folder('', shared_link: 'https://www.dropbox.com/sh/cut/cut')
but I'm unable to iterate through the entries:
result.entries
ArgumentError: Invalid value for `path_lower`: nil.
from /cut/dropbox_api-0.1.12/lib/dropbox_api/metadata/base.rb:62:in `rescue in []=`
I don't know it supporting shared folders is on the roadmap. I just wanted to let you guys know that it does not work.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.