Hi, At first glance that seems along like lines of how I would do it yes. Good job figuring out the search queries. :-) You could also use something like client.SearchExistingFileSchema , but the way you did it is more generic, so it will serve you to know how to do it that way anyway. And I don't think LoadAllChunks is necessary. btw, you can also inspire yourself from all the other existing 3rd party clients within the project to see how they interact with the API, namely: the web UI (server/perkeepd/ui), and the apps (app/publisher and app/scanningcabinet).
On Tue, 4 Sep 2018 at 21:06, Christian von Kietzell <[email protected]> wrote: > > 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. -- 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.
