如何使用rsync将实时URL中的图像写入本地系统 [英] How to write a image from the live url into local system using rsync

查看:76
本文介绍了如何使用rsync将实时URL中的图像写入本地系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存图像或加载此示例中的图像图片链接连接到我的计算机,进入终端.有人可以告诉我如何使用终端命令保存图像吗?路径是:-/home/iron/go/src/

I want to save a image or load a image which is on this example image link into my computer using rsync command into the terminal. Can anybody tell me how to save the image using terminal command? Path is:- /home/iron/go/src/

推荐答案

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

Here I'm adding my answer to load a image from server to the local system or you can say remote machine to local machine

这是小代码

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

我认为它满足了您的问题.

I think it satisfied your question.

这篇关于如何使用rsync将实时URL中的图像写入本地系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆