Skip to content

Download large files via stream #47

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

Open
Mbuckley0 opened this issue Oct 14, 2021 · 2 comments
Open

Download large files via stream #47

Mbuckley0 opened this issue Oct 14, 2021 · 2 comments

Comments

@Mbuckley0
Copy link

I can see that there is a way you can upload files via a stream but is there a way to download a file via stream to try and speed up the process.

@klondikemarlen
Copy link

Combining the information from https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/dn450841(v=office.15)#file-resource and https://github.com/taf2/curb/blob/13144ec5d50ffea0460298cc5de8a0b33db78d22/lib/curl/easy.rb#L446

I would say the solution is something like

File.open('/tmp/some-file', 'wb') do |file|
  body = nil
  skip_json = true
  site.query :get, 'https://my.site.com/some/site/some/path/to/file.pdf', body, skip_json do |curl|
     curl.headers["Accept"] = 'application/octet-stream'
     curl.headers["Content-Type"] = 'application/json;odata=verbose'
     curl.on_body do |data|
        file.write data # or whatever else you want to do with the data.

        data.length # curl.on_body block must return the data length
      end
  end
end

@klondikemarlen
Copy link

Arguably

folder = site.folder '/SiteAssets/documents' # Get a folder by server relative path
file = folder.file_from_name('some-file-name.pdf')
file.download
# or 
file.download_to_file(some_file)

is actually doing the same thing.

See

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

No branches or pull requests

2 participants