如何使用 rsync 将实时 url 中的图像写入本地系统
How to write a image from the live url into local system using rsync
我想使用终端中的 rsync 命令将此示例 image link 中的图像保存或加载到我的计算机中。谁能告诉我如何使用终端命令保存图像?路径是:- /home/iron/go/src/
我在这里添加我的答案,将图像从服务器加载到本地系统,或者你可以说远程机器到本地机器
这是小代码
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
url := "https://www.bookingkoala.com/wp-content/uploads/2017/03/cropped-logo.png" // your url
// don't worry about errors
response, e := http.Get(url) // getting data from the url
if e != nil || response == nil {
return
}
defer response.Body.Close()
//open a file for writing
file, err := os.Create("/home/iron/go/src/abc/sada.png") // define path and file name where you want to store the image.
if err != nil || response == nil {
// log.Fatal(err)
return
}
defer file.Close()
// Use io.Copy to just dump the response body to the file. This supports huge files
_, err = io.Copy(file, response.Body) // it will make or copy a file of the image in the link
if err != nil {
log.Fatal(err)
}
fmt.Println("Success!")
}
我认为它满足了你的问题。
我想使用终端中的 rsync 命令将此示例 image link 中的图像保存或加载到我的计算机中。谁能告诉我如何使用终端命令保存图像?路径是:- /home/iron/go/src/
我在这里添加我的答案,将图像从服务器加载到本地系统,或者你可以说远程机器到本地机器
这是小代码
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
url := "https://www.bookingkoala.com/wp-content/uploads/2017/03/cropped-logo.png" // your url
// don't worry about errors
response, e := http.Get(url) // getting data from the url
if e != nil || response == nil {
return
}
defer response.Body.Close()
//open a file for writing
file, err := os.Create("/home/iron/go/src/abc/sada.png") // define path and file name where you want to store the image.
if err != nil || response == nil {
// log.Fatal(err)
return
}
defer file.Close()
// Use io.Copy to just dump the response body to the file. This supports huge files
_, err = io.Copy(file, response.Body) // it will make or copy a file of the image in the link
if err != nil {
log.Fatal(err)
}
fmt.Println("Success!")
}
我认为它满足了你的问题。