laixhe / goimg Goto Github PK
View Code? Open in Web Editor NEWGolang 轻量级的图片服务器
Golang 轻量级的图片服务器
我使用发现图片上传后过段时间会失效, 图片文件丢失了,请问是有时间限制吗?
希望能支持gif,bmp这些,就是更多些的图片
go run main.go
img/51525457101/e4369ddffce167352745db788b3407fa/ dirPath
mkdir img/51525457101: permission denied err
老哥这个怎么处理呢
复现步骤
go build
./goimg
{
"success": false,
"code": 7,
"msg": "创建目录失败",
"version": "v0.1.1",
"data": {
"size": 0,
"mime": "",
"imgid": ""
}
}
操作系统: Arch Linux
Go: go version go1.15.6 linux/amd64
猜测可能是err = os.MkdirAll(dirPath, 0666) 这里的0666 设置有问题
goimg/uphand/controller.go
这个文件中的第141行的filePath不带扩展名,在保存文件的时候不会有问题吗?
randomName := golibs.GetGuid()
fileName := randomName
if imgtype == api_common.PNG {
fileName += ".png"
} else if imgtype == api_common.JPG || imgtype == api_common.JPEG {
fileName += ".jpg"
} else if imgtype == api_common.GIF {
fileName += ".gif"
} else {
res.Code = models.StatusImgIsType
res.Msg = models.StatusText(models.StatusImgIsType)
w.Write(models.ResponseJson(res))
return
}
filePath := dirPath + fileName // 文件路径
上面这个会不会好点?
或者:
randomName := golibs.GetGuid()
fileName := randomName + "." + imgtype
filePath := dirPath + fileName // 文件路径
单纯的通过上传图片文件的后缀来决定图片的类型不一定正确,比如,我把一个 .jpg 文件的后缀改成 .png,但是实际的图片类型其实还是 .jpg,而不是 .png
更可靠的方式是通过二进制文件的magic number signature 来判断,我发现一个项目 filetype ,基本原理就是通过二进制文件的 magic number signature 判断文件的类型,当然也包括图片文件
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.