I try to add files on the blobstore, i have found some examples with go but these are examples with a html template and i now send images from my react-native app that calls my api in go to add file on blobstore.
So how to add a file on blobstore with a file i get with r.FormFile()
in go ?
example i have found :
func sampleHandler(w http.ResponseWriter, r *http.Request) {
// [START uploading_a_blob_2]
var rootTemplate = template.Must(template.New("root").Parse(rootTemplateHTML))
const rootTemplateHTML = `
<html><body>
<form action="{{.}}" method="POST" enctype="multipart/form-data">
Upload File: <input type="file" name="file"><br>
<input type="submit" name="submit" value="Submit">
</form></body></html>
`
// [END uploading_a_blob_2]
// [START uploading_a_blob_1]
ctx := appengine.NewContext(r)
uploadURL, err := blobstore.UploadURL(ctx, "/upload", nil)
if err != nil {
serveError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "text/html")
err = rootTemplate.Execute(w, uploadURL)
if err != nil {
log.Errorf(ctx, "%v", err)
}
// [END uploading_a_blob_1]
}
Thank's :)
My suggestion would be to provide a small JSON API that your React Native app can call that will give you back an upload URL generated by blobstore.UploadURL
. You should then be able to POST to the URL as normal.