Esempio n. 1
0
func sendFileBlobs(c *blobserv.Client, part *multipart.Part) (respMeta map[string]interface{}) {
	meta := blob.NewMeta()
	defer func() {
		respMeta = map[string]interface{}{}
		respMeta["name"] = meta.Name
		respMeta["size"] = meta.Size

		if r := recover(); r != nil {
			respMeta["error"] = r.(error).Error()
		}
	}()

	obj := blob.NewObject()
	meta.RcasObjectRef = obj.Ref()
	meta.Name = part.FileName()

	data, err := ioutil.ReadAll(part)
	util.Check(err)

	meta.Size = int64(len(data))

	blobs := blob.SplitRaw(data, blob.DefaultChunkSize)
	meta.ContentRefs = blob.RefsFor(blobs)

	m, err := blob.Marshal(meta)
	util.Check(err)

	blobs = append(blobs, m, obj)
	for _, b := range blobs {
		err = c.PutBlob(b)
		util.Check(err)
	}

	return respMeta
}
Esempio n. 2
0
func stripBlobs(c *blobserv.Client) []*shortblob {
	blobs, err := c.BlobsBackward(time.Now(), 20, 0)
	util.Check(err)

	short := []*shortblob{}
	for _, b := range blobs {
		buf := bytes.NewBuffer([]byte{})
		json.Indent(buf, b.Content(), "", "    ")
		short = append(short, &shortblob{b.Ref(), buf.String()})
	}

	return short
}
Esempio n. 3
0
func putnote(c *blobserv.Client, w http.ResponseWriter, req *http.Request) {
	defer util.DeferWrite(w)

	body, err := ioutil.ReadAll(req.Body)
	util.Check(err)

	var note map[string]interface{}
	err = json.Unmarshal(body, &note)
	util.Check(err)

	note[blob.Type] = myType

	b, err := blob.Marshal(note)
	util.Check(err)

	err = c.PutBlob(b)
	util.Check(err)

	w.Write(b.Content())
}