I'm trying to update the WhatsApp profile picture using facebook graph API in Go. As the graph API only accepts the image file as binary, and my image file is already uploaded in google bucket, I need to convert the file to binary.
When I try to read file from GCS by creating MediaURL and below code returns error. It says "no such file or directory". The url is opened in the browser.
bytes, err := ioutil.ReadFile(gcsUrl)
CodePudding user response:
You got an error because it tries to resolve the path on your local, not remote path
first, you need to pull the image
resp, err := http.Get(gcsUrl)
if err != nil {
return "", fmt.Errorf("GET error: %v", err)
}
defer resp.Body.Close()
then you can read that data data, err := ioutil.ReadAll(resp.Body)
ReadAll takes io.Reader
type data and resp.Body
is compatible to that