I am attempting to upload a JSON array to Google Cloud Storage, which is posted by an App Engine application using the code below:
saveData : function saveData() {
var _this = this,
save = this.shadowRoot.querySelector('#save-data'),
subData = JSON.stringify(_this.app.userSession);
save.url="url";
save.body = subData;
save.go();
}
The posted message is processed in the 'go' function with the following code. Currently, I can create a folder in the cloud storage bucket named after the user ID. However, my goal is to copy the entire JSON array (variable f in the code) into this folder. When I tried using io.Copy(wc, f), I encountered the error message below:
cannot use content (type userData) as type io.Reader in argument to io.Copy: userData does not implement io.Reader (missing Read method)
Clearly, there is something incorrect in my implementation, and as a newcomer to Go programming, I'm struggling to find a solution. Can anyone provide assistance?
package expt
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"golang.org/x/net/context"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/appengine"
"google.golang.org/appengine/file"
"google.golang.org/appengine/urlfetch"
"google.golang.org/cloud"
"google.golang.org/cloud/storage"
)
var bucket = "expt"
func init() {
http.HandleFunc("/", handleStatic)
http.HandleFunc("/save", saveJson)
}
...
// Additional code continues here