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

object storage v1: Helper functions for Uploading and Downloading #46

Open
jtopjian opened this issue Jun 2, 2018 · 1 comment
Open

Comments

@jtopjian
Copy link
Contributor

jtopjian commented Jun 2, 2018

Gophercloud contains fairly feature complete support for Object Storage, however the functions are very basic and low-level. One would have to write a good amount of code in order to have more robust uploading and downloading.

It would be beneficial to include these functions here. The functionality could/should use python-swiftclient as the basis:

https://github.com/openstack/python-swiftclient/blob/e65070964c7b1e04119c87e5f344d39358780d18/swiftclient/service.py

@majewsky
Copy link

majewsky commented Aug 14, 2019

I see you implemented something like this already in #47. Alternatively, you could have the documentation point users to https://github.com/majewsky/schwift, which provides a nice object-oriented Swift client API on top of Gophercloud auth.

For example, this is what segmented uploading looks like in Schwift: (error handling elided)

var client *gophercloud.ServiceClient //has already been obtained
account, err := gopherschwift.Wrap(client)
container, err := account.Container("example").EnsureExists()
segmentContainer, err := account.Container("example_segments").EnsureExists()
largeObj, err := container.Object("linux-5.0.0.tar.gz").AsNewLargeObject(
  schwift.SegmentingOptions{SegmentContainer: segmentContainer},
  &schwift.TruncateOptions{DeleteSegments: true}, //cleanup existing segments, if necessary
)
file, err := os.Open("./linux-5.0.0.tar.gz")
segmentSize := 1<<30
err := largeObj.Append(file, segmentSize, nil)
err := largeObj.WriteManifest(nil)

If you want to add extra metadata to the object, replace the last line by something like:

hdr := NewObjectHeaders()
obj.ContentType().Set("application/tar")
obj.ExpiresAt().Set(time.Now().Add(24 * time.Hour))
err := largeObj.WriteManifest(hdr.ToOpts())

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