Salesforce 将blob转换为图像并保存到本地文件夹-Apex
我可以从richtext字段中读取blob,现在需要将其另存为.jgp/png到我的本地文件夹中Salesforce 将blob转换为图像并保存到本地文件夹-Apex,salesforce,apex-code,apex,Salesforce,Apex Code,Apex,我可以从richtext字段中读取blob,现在需要将其另存为.jgp/png到我的本地文件夹中 Matcher imgMatcher = Pattern.compile( '<img(.+?)>' ).matcher(con.Photo__c); String imageURL = imageTag.substringBetween( ' src="', '"' ); String decodedURL = imageURL.unescapeHtml4(); PageReferen
Matcher imgMatcher = Pattern.compile( '<img(.+?)>' ).matcher(con.Photo__c);
String imageURL = imageTag.substringBetween( ' src="', '"' );
String decodedURL = imageURL.unescapeHtml4();
PageReference page = new PageReference( decodedURL );
Blob bodyBlob = page.getContent();
//something like this
File file=new File('c://myimages');
image img=new image(bodyBlob);
img.fomrat='jpg';
img.title='myphoto';
file.save(img);
Matcher-imgMatcher=Pattern.compile('
所以它以图像的形式存储在我的本地文件夹中。这是否可以使用apex(salesforce)实现Salesforce无法写入您的文件系统。您有几个选项,可以保存到附件记录或文档记录并从那里下载,或者您可以通过visualforce页面公开该文件,如果您根本不想将其存储在Salesforce中,可以将其作为附件下载:
<apex:page contentType="img/jpg" extensions="xxx">{!image}</apex:page>
{!image}
这就是我如何实现的,一旦保存到salesforce文件夹,我就从那里下载了图像,希望它能帮助别人
Matcher imgMatcher = Pattern.compile( '<img(.+?)>' ).matcher(con.Photo__c);
String imageURL = imageTag.substringBetween( ' src="', '"' );
String decodedURL = imageURL.unescapeHtml4();
PageReference page = new PageReference( decodedURL );
Blob bodyBlob = page.getContent();
Document doc=new Document();
doc.Body=bodyBlob;
doc.FolderId='salesforce folder Id';
doc.Name=con.name;
doc.Type='jpg';
Insert doc;
Matcher imgMatcher=Pattern.compile('谢谢,是的,salesforce无法写入文件系统。我将它们作为文档保存到salesforce文件夹并从那里下载。