I am trying to upload a file in my GAE app. How do I the upload of a file in Google App Engine using Go and using the r.FormValue()
?
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- What is the best way to do a search in a large fil
- Spring Integration - Inbound file endpoint. How to
- Golang mongodb aggregation
- __call__() missing 1 required positional argument:
相关文章
- Can I run a single test in a suite?
- Is there a size limit for HTTP response headers on
- How to check if a request was cancelled
- What is the correct way to declare and use a FILE
- Is it possible to implement an interface with unex
- appcfg.py command not found
- Making new files automatically executable?
- How to access value of first index of array in Go
I have tried the full example from here https://developers.google.com/appengine/docs/go/blobstore/overview, and it worked fine doing the upload in blobstore and serving it.
But inserting extra post values to be saved somewhere in the datastore erases the values of "r.FormValue() "? Please refer to the code below
Is it not possible to combine the upload with regular data? How come the values of r.FormValue() seems to disappear except for the file (input file type)? Even if I would have to force upload first before associating the blobkey, as the result of the upload, to other data, it would not be possible since I could not pass any r.FormValue() to the upload handler(which like I said becomes empty, or would raised an error when accessed prior the blobs, _, err := blobstore.ParseUpload(r) statement). I hope someone could help me solve this problem. Thank you!
You have to go through the Blobstore Go API Overview to get an idea and there is a full example on how could you store & serve user data on Google App Engine using Go.
I would suggest you to do that example in a completely separate application, so you'll be able to experiment with it for a while before trying to integrate it to your already existing one.
In addition to using the Blobstore API, you can just use the
Request.FormFile()
method to get the file upload content. Use net\http package documentation for additional help.Using the Request directly allows you to skip setting up an
blobstore.UploadUrl()
before handling the upload POST message.A simple example would be:
I managed to solve my problem by using the middle return param, "other". These code below are inside the upload handler
Then assign corresponding formkey
And use it like this in my struct value assignment
Not 100% sure this is the right thing but this solves my problem and it is now uploading the image to blobstore and saving other data and blobkey to datastore.
Hope this could help others too.