image - 如何使用 rsync 将实时 url 中的图像写入本地系统
问题描述
我想使用 rsync 命令将这个示例图像链接上的图像保存或加载到我的计算机到终端中。谁能告诉我如何使用终端命令保存图像?路径是:-/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!")
}
我认为它满足了你的问题。
推荐阅读
- html - 在 div 上处理 div 的最佳做法是什么。(也是响应式的)
- vba - 有没有办法检查是否使用 VBA 代码呈现 PowerPoint?
- java - FactoryBean @Resource 与 @Autowired
- python-3.x - 获取缺失的权限
- flutter - 交错颤动动画列表项生成器动画
- css - id 名称为 id-Output Url 的输入无法选择
- node.js - 在nodejs上构建代码时JavaScript堆内存不足
- node.js - 如何使用 Express 和 Apollo-Server 获取 HTTP 授权标头
- java - 如何在android studio上修复“模拟器:进程以退出代码-2147483645完成”?
- apache-flink - Flink re-scalable keyed stream 有状态函数