首页 > 解决方案 > 如何使用 rsync 将实时 url 中的图像写入本地系统

问题描述

我想使用 rsync 命令将这个示例图像链接上的图像保存或加载到我的计算机到终端中。谁能告诉我如何使用终端命令保存图像?路径是:-/home/iron/go/src/

标签: imageterminalrsync

解决方案


在这里,我添加了将图像从服务器加载到本地系统的答案,或者您可以说远程机器到本地机器

这是小代码

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!")
}

我认为它满足了你的问题。


推荐阅读