2

My app uses silverstripe to manage a large number of files for downloading/accessing them and some relational metadata.

One requirement is that the files be accessible externally via an API. I have set up the Restfulserver module (https://packagist.org/packages/silverstripe/restfulserver) to accomplish this.

And have extended the File model to allow restful access:

class FileExtension extends DataExtension
{
    ...

    private static $api_access = true;

    ...
}

This lets me get and download a file with no problems using a GET:

silverstripe/public/api/v1/Silverstripe-Assets-File/(ID)

Which gives me the necessary data to hit the assets/{hash}/(fileName) and download the file.

But it doesn't seem to give me the means to POST a file. POSTing here simply creates the a File record but with no accompanying file in the assets folder. Manually dropping a file in the folder doesnj't work because it is not referenced by the record and does not have an associated Hash.

So how to I upload files without a page controller?

scrowler
  • 24,273
  • 9
  • 60
  • 92
Samih
  • 1,078
  • 9
  • 15
  • 1
    I don't know if the `restfulserver` module supports file upload out-of-the-box. I think you need to create a custom controller action for this. You could set the default POST file endpoint as the route for your controller action. This way you keep your endpoint URIs consistent. – Conny Nyman Jan 15 '19 at 09:01

0 Answers0