// BufPut - buffered put - saves its contents to memory, to memcache and the datastore // Todo: Don't buffer in local memory. func BufPut(w http.ResponseWriter, r *http.Request, wb WrapBlob, skey string) (mkk string, errClosure error) { c := appengine.NewContext(r) t := fmt.Sprintf("%T", wb) mkk = t + "__" + skey // kombi key errClosure = datastore.RunInTransaction(c, func(c appengine.Context) error { dskey1 := datastore.NewKey(c, t, skey, 0, nil) _, err := datastore.Put(c, dskey1, &wb) McacheSet(c, mkk, wb) memoryInstanceStore[mkk] = &wb multiCastInstanceCacheChange(w, r, mkk) c.Infof("saved to ds and memcache and instance RAM - combikey is %v", mkk) return err }, nil) util_err.Err_panic(errClosure) return }
// we want to extract the 'image/png' from // "data:image/png;base64,..." //func MimeFromBase64(b *bytes.Buffer)(mime string){ func MimeFromBase64(b io.Reader) (mime string) { // to avoid huge string allocation // we read the first 100 bytes b1 := make([]byte, 100) _, err := b.Read(b1) util_err.Err_panic(err) s := string(b1) pos := base64HeaderPosition(s) if pos > 0 { tmp1 := s[:pos] tmp2 := strings.Split(tmp1, ";") tmp3 := strings.Split(tmp2[0], ":") mime = tmp3[1] } return }