Skip to content
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

上传文件,form状态下预览失败 #406

Open
1 task done
haoqibbbb opened this issue May 11, 2024 · 3 comments
Open
1 task done

上传文件,form状态下预览失败 #406

haoqibbbb opened this issue May 11, 2024 · 3 comments

Comments

@haoqibbbb
Copy link

感谢您支持fast-crud,请按如下规范提交issue
如果有条件,请尽量在github上提交

一、问题描述

上传文件后进行预览, 后台返回的值不是一个完整的url,本地根据value构建文件的url。
行状态下正能正常预览,地址为后端服务器IP+文件相对路径
但是form状态下预览失败,form状态下拼接的是前端IP:http://localhost:8080/

代码截图

image

报错截图

image
image

二、当前使用的库版本

1. fast-crud版本:

版本1.20.2

2. 使用的ui库以及版本

中括号中输入x即选中,或者删除其他,仅保留你正使用的ui库

  • ElementPlus(版本?)
@lvzenglei
Copy link

Me too, Any solution or suggestion?

@lvzenglei
Copy link

lvzenglei commented May 17, 2024

Column: buildUrl; form: ValueBuilder
column: {
component: {
async buildUrl(url: any) {
return url + "?preview=600x600";
}
}
},
valueBuilder(context: ValueBuilderContext) {
if (context.row.file_url) {
if (Array.isArray(context.row.file_url)) {
context.row.file_url = context.row.file_url.map((url: string) => ${import.meta.env.VITE_APT_MEDIA_URL}${url});
} else if (typeof context.row.file_url === 'string') {
context.row.file_url = ${import.meta.env.VITE_APT_MEDIA_URL}${context.row.file_url};
}
}
},
valueResolve(context: ValueBuilderContext) {
if (context.row.file_url) {
const mediaUrl = import.meta.env.VITE_APT_MEDIA_URL; // Store the media URL in a variable for reuse
if (Array.isArray(context.row.file_url)) {
context.row.file_url = context.row.file_url.map((url: string) => url.replace(mediaUrl, ''));
} else if (typeof context.row.file_url === 'string') {
context.row.file_url = context.row.file_url.replace(mediaUrl, '');
}
}
}

@greper
Copy link
Contributor

greper commented Jun 7, 2024

我的示例没有任何问题,我不太清楚你的前端ip是怎么来的,你baseUrl是localhost:8080?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants