Downloaded image is not opening

I’ve this image file shared publicly at google drive: Cashew SC pic - Abdulhadi Khalifah.jpeg - Google Drive

I want to download it at my computer, so I wrote the below code:

package main

import (

func main() {
    // image link, open at browser

	url := ""
    // or
    //	url := ""
    fileName := "file.jpeg"
	fmt.Println("Downloading file...")

	output, err := os.Create(fileName)
	defer output.Close()

	response, err := http.Get(url)
	if err != nil {
		fmt.Println("Error while downloading", url, "-", err)
	defer response.Body.Close()

	n, err := io.Copy(output, response.Body)

	fmt.Println(n, "bytes downloaded")

A file had been downloaded, but once I opened it I got this error:
enter image description here

Have you checked the response’s StatusCode ?

For instance if I put in the browser I get a “NOT FOUND” page

Thanks for your catch, the mistake was in the url, the correct code should be:

	image := ""
	id := image[33:]
	url := "" + id

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.