Hi again,

after looking at Tamás' camproxy and poking around in the API docs for
client, search, and schema I managed to get uploading and downloading a
file done with the following (error handling omitted for brevity):

 // upload
 // get io.Reader r for file "filename"

 ctx := context.Background()
 cl, _ := client.New()
 
 ref, _ := schema.WriteFileFromReader(ctx, cl, filename, r)

I instatiated the client without any options for now. The upload seems
to work fine. Downloading a file when I've got just its name I found a
little more tricky. Am I right in thinking that I need to do a search
for the filename and then use the resulting blobref to get at the
contents. That what I did and it worked.

 // search for filename
 qry := &search.SearchQuery {
   Constraint: &search.Constraint {
     File: &search.FileConstraint {
       FileName: &search.StringConstraint{Equals: filename},
     },
   },
   Limit: 1,
 }
 sr, _ := cl.Query(ctx, qry)
 if len(sr.Blobs) < 1 {
   // file not found
 }

 // download
 rc, _ := schema.NewFileReader(ctx, cl, sr.Blobs[0].Blob)
 defer rc.Close()
 rc.LoadAllChunks()
 // io.Copy or whatever contents from rc

Is this more or less the right way to do it or am I doing it wrong/too
complicated/...? For some reason using "Expression" in SearchQuery
didn't work when the filename contained spaces, even when I put it in
double quotes (filename:"file with spaces.jpg"). But I didn't yet bother
to find out why, because the explicit way using Constraint worked.


Cheers,
Chris

On Tue, Sep 04, 2018 at 08:16:49AM +0200, Gulácsi Tamás wrote:
> Take a look at github.com/tgulacsi/camproxy - it uses ther Perkeep 
> (camlistore)
> client libraries to provide a simple PUT/GET storage backend functionality.

-- 
You received this message because you are subscribed to the Google Groups 
"Perkeep" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to