我写了一个简单的 Visualforce 页面,让用户上传图像文件
将文件保存到 ContentVersion
目的。
现在 我想在我的自定义 Visualforce 页面中显示保存的图像。 甚至有可能吗?
看起来像 <apex:image>
不能使用。还有 <img href="{!cv.contentVersion}"...>
没有运气。
真正的问题是我确实成功上传了图像文件,但它的 URL 是什么?
我在谷歌之外用随机 URL 进行了测试,我可以显示图像(如/../..some.jpg")。但我无法弄清楚已上传到 contentversion 的图像文件的绝对 URL 是什么.
注意:这不是静态资源,因为我的用户可能会上传图片以经常更改他们的用户图片。
代码
public with sharing class ImageUploadTestController {
public blob file { get; set; }
public String imageFilePath { get; set; }
public ContentVersion cv { get; set; }
public ImageUploadTestController() {
cv = [select id, versionData, title, pathOnClient FROM ContentVersion limit 1];
}
//fill out the inputFile field and press go. This will upload file to the server
public PageReference go() {
ContentVersion v = new ContentVersion();
v.versionData = file;
v.title = 'some title';
v.pathOnClient ='/foo.jpeg';
insert v;
return new PageReference('/' + v.id);
}
//v.id sample
//069A00000009Ux3
}//end class
Visualforce 页面
<apex:page controller="ImageUploadTestController">
<apex:form >
<apex:inputFile value="{!file}" />
<apex:commandbutton action="{!go}" value="go"/>
</apex:form>
<!-- none of below works!! :( -->
<a href="/{!cv.id}">{!cv.title} {!cv.pathOnClient}</a>
<a href="https://na7.salesforce.com/069A00000009FG4"></a>
<apex:image value="/069A00000009Ux3" width="220" height="55"/>
</apex:page>
最佳答案
我认为目前无法从内容中提供它 ScottW 提供的格式适用于文档。
我所做的另一个选择是将包含我的图像的 zip 文件上传到静态资源,然后可以引用该文件。
关于image - Salesforce - 是否可以将 ContentVersion 中的图像文件显示到自定义 Visualforce 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5457509/