image - Salesforce - 是否可以将 ContentVersion 中的图像文件显示到自定义 Visualforce 页面?

标签 image upload salesforce visualforce apex-code

我写了一个简单的 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/

相关文章:

python - 延迟打开 Tkinter 多个 Windows (Python)

java - Swing:获取JFrame的图像

salesforce - 使用 SOQL 查询 Salesforce 对象列名称

javascript - 用于导入用户帐户联系人的 Salesforce API

salesforce - 如何在 Java 7 中为 Axis 1 Web 服务客户端启用 TLS1.1

Java IO 无法读取输入文件?

c# - 在javascript函数中使用asp.net的图像组件

java - 从网络摄像头代码将图片上传到 Twitter 每次都上传相同的照片

c# - 如何使用 OAuth2 访问 token (.NET) 通过 API 上传 Youtube 视频?

asp.net - 如何在 ASP.NET 上上传 10gb 文件