当前位置: 首页>>代码示例>>Golang>>正文


Golang blobstore.ParseUpload函数代码示例

本文整理汇总了Golang中appengine/blobstore.ParseUpload函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseUpload函数的具体用法?Golang ParseUpload怎么用?Golang ParseUpload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseUpload函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: UploadHandler

//UploadHandler handles upload of a new presentation and saving its metadata
//to Datastore.
//
//Doesn't support filenames with non-ASCII characters. GAE encodes
//those into base-64 string with encoding prefixed and I don't want
//to include additional logic to differentiate between ASCII and
//non-ASCII filenames.
func UploadHandler(c util.Context) (err error) {
	blobs, formVal, err := blobstore.ParseUpload(c.R)
	if err != nil {
		return
	}
	blob := blobs["file"][0]
	fn := strings.Split(blob.Filename, ".")
	fileType := fn[len(fn)-1]

	var active bool
	if len(formVal["activate"]) == 0 {
		active = false
	} else {
		active = true
	}

	name := formVal["name"][0]
	if name == "" {
		name = "Neznáma prezentácia z " + time.Now().Format("2.1.2006")
	}

	p, err := presentation.Make(blob.BlobKey, fileType, name, []byte(formVal["description"][0]), active, c)
	if err != nil {
		return
	}

	http.Redirect(c.W, c.R, "/admin/presentation/"+p.Key().Encode(), 303)
	return
}
开发者ID:sellweek,项目名称:TOGY-server,代码行数:36,代码来源:broadcast.go

示例2: handleDoUpload

func handleDoUpload(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		serveError(c, w, err)
		return
	}
	file := blobs["file"]
	if len(file) == 0 {
		c.Errorf("no file uploaded")
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	img := Image{
		BlobKey: file[0].BlobKey,
	}

	key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "image", nil), &img)
	if err != nil {
		c.Errorf("datastore fail")
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	http.Redirect(w, r, "/"+key.Encode(), http.StatusFound)
}
开发者ID:dannysu,项目名称:imagedatastore,代码行数:27,代码来源:server.go

示例3: handleUploadImage

// 画像のアップロード
func handleUploadImage(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		http.Error(w, "リクエストエラー", http.StatusBadRequest)
		return
	}
	c := appengine.NewContext(r)
	g := goon.FromContext(c)
	key := r.FormValue("key")
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	image := blobs["uploadFile"]
	if len(image) == 0 {
		http.Error(w, "画像がありません", http.StatusInternalServerError)
		return
	}
	ibi := ImageBlobInfo{
		Id:      key,
		BlobKey: string(image[0].BlobKey),
	}
	//	keys := datastore.NewIncompleteKey(c, "blobInfo", nil)
	//	_, err = datastore.Put(c, keys, &ibInfo)
	g.Put(&ibi)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Write([]byte(ibi.BlobKey))
}
开发者ID:mako0715,项目名称:sample,代码行数:32,代码来源:endpoints_image.go

示例4: uploadHandler

// uploadHandler handles the image upload and stores a new Overlay in the
// datastore. If successful, it writes the Overlay's key to the response.
func uploadHandler(c appengine.Context, w http.ResponseWriter, r *http.Request) *appError {
	// Handle the upload, and get the image's BlobKey.
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		return appErrorf(err, "could not parse blobs from blobstore upload")
	}
	b := blobs["overlay"]
	if len(b) < 1 {
		return appErrorf(nil, "could not find overlay blob")
	}
	bk := b[0].BlobKey

	// Fetch image from blob store to find its width and height.
	m, err := imageBlob(c, bk)
	if err != nil {
		return appErrorf(err, "could not get image")
	}

	// Create and store a new Overlay in the datastore.
	o := &Overlay{
		Owner:  user.Current(c).ID,
		Image:  bk,
		Width:  m.Bounds().Dx(),
		Height: m.Bounds().Dy(),
	}
	k := datastore.NewIncompleteKey(c, "Overlay", nil)
	k, err = datastore.Put(c, k, o)
	if err != nil {
		return appErrorf(err, "could not save new overlay to datastore")
	}

	// It will be known hereafter by its datastore-provided key.
	fmt.Fprintf(w, "%s", k.Encode())
	return nil
}
开发者ID:TheAustrianPro,项目名称:overlay-tiler,代码行数:37,代码来源:http.go

示例5: uploadFile

// Common function for uploading a file
func uploadFile(c appengine.Context, r *http.Request, currentFiles []model.File) ([]model.File, error) {
	// Parse file uploads
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		return currentFiles, err
	}
	files := blobs["file"]
	if len(files) == 0 {
		c.Errorf("no file uploaded")
		return currentFiles, nil
	}

	// Add the new file
	for i := range files {
		newFile := model.File{files[i].Filename, files[i].BlobKey}

		// Check if it already exists
		exists := false
		for j := range currentFiles {
			if currentFiles[j].Filename == newFile.Filename {
				// Overwrite
				// TODO: delete the old file
				currentFiles[j] = newFile
				exists = true
				break
			}
		}

		if !exists {
			currentFiles = append(currentFiles, newFile)
		}
	}

	return currentFiles, nil
}
开发者ID:hamax,项目名称:avy,代码行数:36,代码来源:files.go

示例6: upload

func upload(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	file := blobs["file"]
	if len(file) == 0 {
		c.Errorf("No file uploaded")
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	reader := blobstore.NewReader(c, file[0].BlobKey)
	var pkg *Package
	switch file[0].ContentType {
	case "application/x-tar":
		pkg, err = parsePackageVarsFromTar(bufio.NewReader(reader))
		if err == nil {
			pkg.Type = TAR
		}
	case "application/octet-stream":
		pkg, err = parsePackageVarsFromFile(bufio.NewReader(reader))
		if err == nil {
			pkg.Type = SINGLE
		}
	default:
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	if err != nil {
		c.Errorf(fmt.Sprintf("Error reading from upload: %v", err))
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	key := packageKey(c, pkg.Name)
	_, err = datastore.Put(c, key, pkg)
	if err != nil {
		c.Errorf(fmt.Sprintf("Failed to save package %v", pkg.Name))
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	contents := Contents{
		BlobKey:    file[0].BlobKey,
		Version:    pkg.LatestVersion,
		UploadTime: time.Now().UTC(),
	}
	_, err = datastore.Put(c, versionKey(c, pkg.LatestVersion, key), &contents)
	if err != nil {
		c.Errorf(
			fmt.Sprintf(
				"Failed to save contents for version %v, package %v",
				pkg.LatestVersion, pkg.Name))
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	http.Redirect(w, r, "/upload_complete.html?package="+
		url.QueryEscape(pkg.Name), http.StatusFound)
}
开发者ID:ssaavedra,项目名称:elpa-on-appengine,代码行数:59,代码来源:elpa.go

示例7: handleCreateBill

func handleCreateBill(ctx *Context, w http.ResponseWriter, r *http.Request) error {
	errs := []string{}

	blobs, fields, err := blobstore.ParseUpload(ctx.r)

	ctx.Debugf("Blobs: %v", blobs)

	if err != nil {
		return err
	}

	//vendor := getFormFieldString(fields, "vendor")
	amt := getFormFieldInt(fields, "amount")
	if amt <= 0 {
		errs = append(errs, "Amount must be greater than 0")
	}

	vendorID := getFormFieldString(fields, "vendor")
	if vendorID == "" {
		errs = append(errs, "You must choose a vendor for the bill")
	}

	file := blobs["file"]
	if len(file) == 0 {
		errs = append(errs, "You must upload a bill file")
	}

	if len(errs) > 0 {
		return renderBillForm(ctx, errs)
	}

	v, err := ctx.GetVendorByID(vendorID)

	if err != nil {
		return err
	}

	b := Bill{
		Amt:        amt,
		PostedOn:   time.Now(),
		VendorKey:  v.Key,
		CompanyKey: v.CompanyKey,
		PostedBy:   ctx.user.String(),
		BlobKey:    file[0].BlobKey,
	}

	key := datastore.NewIncompleteKey(ctx.c, "Bill", v.CompanyKey)
	_, err = datastore.Put(ctx.c, key, &b)
	if err != nil {
		return err
	}
	ctx.Flash("New bill created successfully!")
	return ctx.Redirect("/admin/bills")
}
开发者ID:nickdufresne,项目名称:GAE-Billing-System,代码行数:54,代码来源:admin.go

示例8: ParseBlobs

/*
 * This one does the magic.
 *
 *      - Gets the uploaded blobs by calling blobstore.ParseUpload()
 *      - Maintains all other values that come from blobstore.
 *      - Hands out the results for further processing.
 */
func ParseBlobs(options *compressionOptions) (blobs map[string][]*blobstore.BlobInfo, other url.Values, err error) {
	blobs, other, err = blobstore.ParseUpload(options.Request)
	if err != nil {
		return
	}
	// Loop through all the blob names
	for keyName, blobSlice := range blobs {
		blobs[keyName] = handleBlobSlice(options, blobSlice)
	}
	return
}
开发者ID:TomiHiltunen,项目名称:GAE-Go-image-optimizer,代码行数:18,代码来源:optimg.go

示例9: UploadHandler

func UploadHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		url, _ := user.LoginURL(c, r.URL.String())
		w.Header().Set("Location", url)
		w.WriteHeader(http.StatusFound)
		return
	}

	id := r.FormValue("id")
	if len(id) > 0 {
		w.Header().Set("Location", "/upload2?id=has_key:"+id)
		w.WriteHeader(http.StatusFound)
		//    uploadTemplate.Execute(w, id)
		return
	}

	blobs, other_params, err := blobstore.ParseUpload(r)
	if len(blobs) == 0 {
		//    w.WriteHeader(http.StatusBadRequest)
		//    fmt.Fprintf(w, "No data '%v'", err)
		w.Header().Set("Location", "/upload2?id=Bad+upload:"+err.String())
		w.WriteHeader(http.StatusFound)
		return
	}
	file := blobs["file_data"]
	if len(file) == 0 {
		//    w.WriteHeader(http.StatusBadRequest)
		//    fmt.Fprintf(w, "No data")
		w.Header().Set("Location", "/upload2?id=No_file_data")
		w.WriteHeader(http.StatusFound)
		return
	}

	key := string(file[0].BlobKey)
	if other_params == nil {
		other_params = make(map[string][]string)
	}
	other_params["key"] = append(other_params["key"], key)
	task := taskqueue.NewPOSTTask("/process/gedcom", other_params)
	task.Name = key
	if err := taskqueue.Add(c, task, ""); err != nil {
		//    http.Error(w, err.String(), http.StatusInternalServerError)
		w.Header().Set("Location", "/upload2?id=bad_task:"+err.String())
		w.WriteHeader(http.StatusFound)
		return
	}

	w.Header().Set("Location", "/upload?id="+key)
	w.WriteHeader(http.StatusFound)
	return
}
开发者ID:phython,项目名称:boyd-search,代码行数:53,代码来源:search.go

示例10: blobAutoUpload

func blobAutoUpload(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)

	// Here we just checked that the upload went through as expected.
	if _, _, err := blobstore.ParseUpload(r); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		c.Errorf("%s", err)
		return
	}
	// Everything seems fine. Signal the other handler using the status code.
	w.WriteHeader(http.StatusCreated)
}
开发者ID:aarzilli,项目名称:tools,代码行数:13,代码来源:blobstore+cmd+line+uploader.go

示例11: Post

func (x UploadRes) Post(c appengine.Context, r *http.Request) (interface{}, error) {
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		return nil, err
	}
	file := blobs["file"]
	if len(file) == 0 {
		return nil, fmt.Errorf("No file uploaded")
	}
	bk := file[0].BlobKey
	PrintInBox(c, "File saved with blobkey", bk)
	return bk, nil
}
开发者ID:ashishthedev,项目名称:climatic_webapp,代码行数:13,代码来源:files.go

示例12: handleUpload

func handleUpload(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		serveError(c, w, err)
		return
	}
	file := blobs["file"]
	if len(file) == 0 {
		c.Errorf("no file uploaded")
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	http.Redirect(w, r, "/serve/?blobKey="+string(file[0].BlobKey), http.StatusFound)
}
开发者ID:ghostnotes,项目名称:HelloGo,代码行数:15,代码来源:blobstoreexample.go

示例13: Save

func Save(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
	ctx := appengine.NewContext(req)

	blobs, vals, err := blobstore.ParseUpload(req)
	if err != nil {
		http.Redirect(rw, req, "/admin/content/"+params["id"]+"?error="+err.Error(), http.StatusFound)
		return
	}

	var title string
	var body string
	var link string
	if len(vals["title"]) > 0 {
		title = vals["title"][0]
	}
	if len(vals["body"]) > 0 {
		body = vals["body"][0]
	}
	if len(vals["link"]) > 0 {
		link = vals["link"][0]
	}

	c := content.Content{}

	intID, err := strconv.Atoi(params["id"])
	if err == nil {
		c.ID = int64(intID)
	}

	c.Get(ctx)
	c.Title = title
	c.Body = body
	c.Link = link

	file := blobs["image"]
	if len(file) != 0 {
		c.Image = fmt.Sprintf("/blob/%s", string(file[0].BlobKey))
	}

	err = c.Save(ctx)
	if err != nil {
		http.Redirect(rw, req, "/admin/content/"+params["id"]+"?error="+err.Error(), http.StatusFound)
		return
	}

	http.Redirect(rw, req, "/admin/content/"+strconv.Itoa(int(c.ID))+"?success=Content saved", http.StatusFound)
	return
}
开发者ID:ninnemana,项目名称:dynamicfab,代码行数:48,代码来源:content.go

示例14: handleUpload

func handleUpload(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	if r.Method != "POST" || r.URL.Path != "/upload" {
		serve404(w)
		return
	}
	c := appengine.NewContext(r)
	blobs, _, err := blobstore.ParseUpload(r)
	if nil != err {
		serveError(c, w, err)
		return
	}
	file := blobs["file"]
	if len(file) == 0 {
		http.Error(w, "No File upload!", http.StatusInternalServerError)
		return
	}
	switch file[0].ContentType {
	/*
	 case "text/xml":
	 page, err := updatePage(c, file[0].BlobKey)
	 if nil != err {
	 serve404(w)
	 return
	 }
	 err = updateTag(c, page)
	 if nil != err {
	 serveError(c, w, err)
	 return
	 }
	 http.Redirect(w, r, "/pages?Title="+page.Title, http.StatusFound)
	*/
	case "image/jpeg", "image/png", "image/webp", "image/gif", "image/bmp", "image/tiff", "image/ico":
		image := Image{file[0].Filename, file[0].BlobKey}
		err = updateImage(c, image)
		if nil != err {
			serveError(c, w, err)
			return
		}
		http.Redirect(w, r, "/images?Name="+file[0].Filename, http.StatusFound)
	default:
		err := errors.New("ContentType " + file[0].ContentType + " not supported!")
		//http.Error(w, "ContentType "+ file[0].ContentType + " not supported!", http.StatusInternalServerError)
		serveError(c, w, err)
	}
	// http.Redirect(w, r, "/serve/?blobKey="+string(file[0].BlobKey), http.StatusFound)
}
开发者ID:henglinli,项目名称:goblog,代码行数:47,代码来源:goblog.go

示例15: BlobUpload

func BlobUpload(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	blobs, _, err := blobstore.ParseUpload(r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	file := blobs["file"]
	if len(file) == 0 {
		c.Errorf("no file upload")
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	http.Redirect(w, r, "/blob/store?blobkey="+string(file[0].BlobKey), http.StatusFound)
}
开发者ID:alvaradopcesar,项目名称:gae-go-example,代码行数:17,代码来源:blob.go


注:本文中的appengine/blobstore.ParseUpload函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。