-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如果我只想修复 图片上传的功能,不想改其他的,需要改哪些代码? #403
Comments
你好,如果你是基于当前仓库的源码修改的,可以找到以下代码: Lines 1045 to 1068 in c40826c
将其修改为本地: let uploadImage = (file,callback)=>{
let reader = new FileReader();
reader.onload = function(){
// 这里能获取到文件的Base64
console.log(reader.result)
callback && callback(null,{data: reader.result})
}
reader.readAsDataURL(file)
} 如果你想优化显示,可以使用 let key = URL.createObjectURL(imageFile)
参考: |
emmm 我的版本是 Valine v1.4.14
我找到了这部分代码 是否改这段代码 可以将 图片上传到我自己的图床呢
Q=function(e,t){
var n=new FormData;
n.append("image",e),
y.default.ajax({
type:"post",
url:"https://pic.alexhchu.com/api/upload",
data:n,
success:function(e){
t&&t(e)
}
})}}
…------------------ Original message ------------------
From: "YY";
Sendtime: Wednesday, Jun 29, 2022 4:15 PM
To: "xCss/Valine";
Cc: ***@***.***>; "Author";
Subject: Re: [xCss/Valine] 如果我只想修复 图片上传的功能,不想改其他的,需要改哪些代码? (Issue #403)
你好,如果你是基于当前仓库的源码修改的,可以找到以下代码:
https://github.com/xCss/Valine/blob/c40826c5816c98d797a6b1ed8b62bddf73ed4f65/src/index.js#L1045-L1068
将其修改为本地:
let uploadImage = (file,callback)=>{ let reader = new FileReader(); reader.onload = function(){ // 这里能获取到文件的Base64 console.log(reader.result) callback && callback(null,{data: reader.result}) } reader.readAsDataURL(file) }
如果你想优化显示,可以使用URL.createObjectURL来创建blob URL:
let key = URL.createObjectURL(image)
参考:
URL.createObjectURL
FileReader
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
如果是要上传到你自己的图床,直接修改图床地址 返回数据格式应该是类似于这样: {
'code': 200,
'data': 'your image url',
'msg': ''
} 你可以试试看~ |
如果我只想修复 图片上传的功能,不想改其他的,需要改哪些代码? 并未找到 #396 #380 这部分的代码
The text was updated successfully, but these errors were encountered: