ユーザーが画像ファイルをアップロードしてからContentVersion
オブジェクトに保存できる簡単なVisualforceページを1つ作成しました。
保存した画像をカスタムvisualforceページに表示したいと思います。それも可能ですか?<apex:image>
使用できないようです。また<img href="{!cv.contentVersion}"...>
、運がなかった。
本当の問題は、画像ファイルを正常にアップロードしたことですが、そのURLは何ですか?Googleの外部でランダムな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>