我上传了一个帐户的jpeg图像。 JPEG图像文件ID 069i0000001dkl8,它无法通过访问, https://c.na15.content.force.com/servlet/servlet.FileDownload?file=069i0000001dkl8如何获取可下载的附件链接?
有没有一种方式,我可以下载的URL在Salesforce的附件(使用API电话)? 或者有没有一种方法可以通过处理API对象(SObject)中的某些字段来构建可下载的URL?
谢谢。
我上传了一个帐户的jpeg图像。 JPEG图像文件ID 069i0000001dkl8,它无法通过访问, https://c.na15.content.force.com/servlet/servlet.FileDownload?file=069i0000001dkl8如何获取可下载的附件链接?
有没有一种方式,我可以下载的URL在Salesforce的附件(使用API电话)? 或者有没有一种方法可以通过处理API对象(SObject)中的某些字段来构建可下载的URL?
谢谢。
从技术上说,你是在处理ContentDocument(069键前缀)和ContentVersion(068键前缀)记录,而不是一个Attachment(00P键前缀)。
看一看数据模型为Content Objects:
您可以使用SOQL创建查询,将让你的ContentDocument正确ContentVersion。然后可以使用生成的ID创建下载URL。
或者,您可以直接通过API从ContentVersion获取附件的二进制内容。
顺便提一下,Salesforce Stackexchange网站是询问Salesforce特定问题的好地方。
冬季15 Salesforce使这成为可能。您可以创建一个类将附件转换为ContentVersion和ContentDistribution。然后传递用户ContentDistribution的DistributionPublicUrl字段。
代码会是这样的
list<Attachment> invoices = [select id, name, body from attachment limit 10];
list<ContentVersion> contents = new list<ContentVersion>();
list<ContentDistribution> dists = new list<ContentDistribution>();
for(Attachment inv: invoices){
ContentVersion cont = new ContentVersion();
cont.Title = inv.Name;
cont.PathOnClient = inv.Name;
cont.VersionData = inv.Body;
contents.add(cont);
}
insert contents;
for(ContentVersion cont : contents){
ContentDistribution cd = new ContentDistribution();
cd.name = cont.Title;
cd.ContentVersionId = cont.id;
cd.PreferencesAllowOriginalDownload = true;
cd.PreferencesAllowPDFDownload = true;
cd.PreferencesAllowViewInBrowser = true;
dists.add(cd);
}
insert dists ;
感谢非常明确答复。当我们有ContentDocument(069键码前缀)或ContentVersion(068键码前缀)ID时,是否还有一种方法可以获得附件ID(00P键码前缀)? – lsc 2014-10-31 08:21:07
@lasithc附件和内容是两种单独的记录类型。你不能直接在它们之间移动。 I.E.这些附件记录与ContentVersion中存储的数据相同。 Attachment和ContentVersion都存储二进制数据。 – 2014-11-01 21:32:28