Retrieve file by ID Silverstripe









up vote
1
down vote

favorite












I am currently using SilverStripe 4.1 and I am trying to retrieve an image from the database and it always returns null.



When I go to the database I see the file reference in the File table. Here is the File table content for the file I was trying to retrieve:



ID | 2583
ClassName | SilverStripeAssetsImage
LastEdited | 2018-11-08 21:05:48
Created | 2018-11-08 21:05:48
Name | logo-v5.png
Title | logo-v5
ShowInSearch| 1
CanViewType | Inherit
CanEditType | Inherit
Version | 1
ParentID | 1753
OwnerID | 10
FileHash | 9e6faa29b752294d2e623bd83b17660df123af62
FileFilename| images/logo-v5.png
FileVariant | NULL


Here are the way I tried:



File::get()->byID(2583); 
Image::get()->byID(2583);
File::get_by_id('SilverStripeAssetsImage', 2583);


In all cases is returning null. Do you know what I am missing here?










share|improve this question



















  • 3




    bit of a guess, but is this something to do with publishing? i.e. do you need to publish it first as it is versioned? alternatively can you do $file = File::get()->filter('Name', 'logo-v5.png')->first();?
    – Barry
    Nov 12 at 13:49






  • 1




    Does the file exist? Is it published? Can you see it in the assets section of the admin area?
    – wmk
    Nov 14 at 20:53














up vote
1
down vote

favorite












I am currently using SilverStripe 4.1 and I am trying to retrieve an image from the database and it always returns null.



When I go to the database I see the file reference in the File table. Here is the File table content for the file I was trying to retrieve:



ID | 2583
ClassName | SilverStripeAssetsImage
LastEdited | 2018-11-08 21:05:48
Created | 2018-11-08 21:05:48
Name | logo-v5.png
Title | logo-v5
ShowInSearch| 1
CanViewType | Inherit
CanEditType | Inherit
Version | 1
ParentID | 1753
OwnerID | 10
FileHash | 9e6faa29b752294d2e623bd83b17660df123af62
FileFilename| images/logo-v5.png
FileVariant | NULL


Here are the way I tried:



File::get()->byID(2583); 
Image::get()->byID(2583);
File::get_by_id('SilverStripeAssetsImage', 2583);


In all cases is returning null. Do you know what I am missing here?










share|improve this question



















  • 3




    bit of a guess, but is this something to do with publishing? i.e. do you need to publish it first as it is versioned? alternatively can you do $file = File::get()->filter('Name', 'logo-v5.png')->first();?
    – Barry
    Nov 12 at 13:49






  • 1




    Does the file exist? Is it published? Can you see it in the assets section of the admin area?
    – wmk
    Nov 14 at 20:53












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am currently using SilverStripe 4.1 and I am trying to retrieve an image from the database and it always returns null.



When I go to the database I see the file reference in the File table. Here is the File table content for the file I was trying to retrieve:



ID | 2583
ClassName | SilverStripeAssetsImage
LastEdited | 2018-11-08 21:05:48
Created | 2018-11-08 21:05:48
Name | logo-v5.png
Title | logo-v5
ShowInSearch| 1
CanViewType | Inherit
CanEditType | Inherit
Version | 1
ParentID | 1753
OwnerID | 10
FileHash | 9e6faa29b752294d2e623bd83b17660df123af62
FileFilename| images/logo-v5.png
FileVariant | NULL


Here are the way I tried:



File::get()->byID(2583); 
Image::get()->byID(2583);
File::get_by_id('SilverStripeAssetsImage', 2583);


In all cases is returning null. Do you know what I am missing here?










share|improve this question















I am currently using SilverStripe 4.1 and I am trying to retrieve an image from the database and it always returns null.



When I go to the database I see the file reference in the File table. Here is the File table content for the file I was trying to retrieve:



ID | 2583
ClassName | SilverStripeAssetsImage
LastEdited | 2018-11-08 21:05:48
Created | 2018-11-08 21:05:48
Name | logo-v5.png
Title | logo-v5
ShowInSearch| 1
CanViewType | Inherit
CanEditType | Inherit
Version | 1
ParentID | 1753
OwnerID | 10
FileHash | 9e6faa29b752294d2e623bd83b17660df123af62
FileFilename| images/logo-v5.png
FileVariant | NULL


Here are the way I tried:



File::get()->byID(2583); 
Image::get()->byID(2583);
File::get_by_id('SilverStripeAssetsImage', 2583);


In all cases is returning null. Do you know what I am missing here?







php image file silverstripe silverstripe-4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 13:45









Barry

3,11571637




3,11571637










asked Nov 9 at 20:55









alysonsm

1,020711




1,020711







  • 3




    bit of a guess, but is this something to do with publishing? i.e. do you need to publish it first as it is versioned? alternatively can you do $file = File::get()->filter('Name', 'logo-v5.png')->first();?
    – Barry
    Nov 12 at 13:49






  • 1




    Does the file exist? Is it published? Can you see it in the assets section of the admin area?
    – wmk
    Nov 14 at 20:53












  • 3




    bit of a guess, but is this something to do with publishing? i.e. do you need to publish it first as it is versioned? alternatively can you do $file = File::get()->filter('Name', 'logo-v5.png')->first();?
    – Barry
    Nov 12 at 13:49






  • 1




    Does the file exist? Is it published? Can you see it in the assets section of the admin area?
    – wmk
    Nov 14 at 20:53







3




3




bit of a guess, but is this something to do with publishing? i.e. do you need to publish it first as it is versioned? alternatively can you do $file = File::get()->filter('Name', 'logo-v5.png')->first();?
– Barry
Nov 12 at 13:49




bit of a guess, but is this something to do with publishing? i.e. do you need to publish it first as it is versioned? alternatively can you do $file = File::get()->filter('Name', 'logo-v5.png')->first();?
– Barry
Nov 12 at 13:49




1




1




Does the file exist? Is it published? Can you see it in the assets section of the admin area?
– wmk
Nov 14 at 20:53




Does the file exist? Is it published? Can you see it in the assets section of the admin area?
– wmk
Nov 14 at 20:53

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233157%2fretrieve-file-by-id-silverstripe%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233157%2fretrieve-file-by-id-silverstripe%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo