3

アカウントの jpeg 画像をアップロードしました。jpeg 画像ファイル ID は 069i0000001dkl8 で、 https: //c.na15.content.force.com/servlet/servlet.FileDownload?file=069i0000001dkl8 経由ではアクセスできません。

ただし、 https: //c.na15.content.force.com/sfc/servlet.shepherd/version/download/068i0000001hwPn?asPdf=false&operationContext=CHATTER からアクセスできます。

Salesforce で (API 呼び出しを使用して) 添付ファイル用のダウンロード可能な URL を取得する方法はありますか? または、API オブジェクト (SObject) のいくつかのフィールドを処理して、ダウンロード可能な URL を作成する方法はありますか?

ありがとう。

4

2 に答える 2

5

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 ;
于 2015-07-06T01:27:51.423 に答える
4

技術的に言えば、添付ファイル( 00Pキー プレフィックス)ではなく、ContentDocument ( 069キー プレフィックス) およびContentVersion ( 068キー プレフィックス) レコードを扱っています。

コンテンツ オブジェクトのデータ モデルをご覧ください。

コンテンツ データ モデル

SOQL を使用して、ContentDocument の正しい ContentVersion を取得するクエリを作成できます。結果の ID を使用して、ダウンロード URL を作成できます。

または、API を介して直接 ContentVersion から添付ファイルのバイナリ コンテンツを取得することもできます。

ちなみに、Salesforce Stackexchangeサイトは、Salesforce 固有の質問をするのに最適な場所です。

于 2014-10-30T23:01:08.380 に答える