I have a Laravel 4.2 API that, when creating a resource, accepts file uploads. The file is retrieved with
Input::file('file')
Now I want to write a script (also in Laravel) that will batch create some resources (so I can't use a HTML form that POSTs to API's endpoint). How can I translate a file path into an instance of UploadedFile
so that Input::file('file')
will pick it up in the API?
Just construct an instance yourself. The API is:
http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/File/UploadedFile.html
So you should be able to do:
Notice: You have to specify the 6th constructing parameter as TRUE, so the UploadedFile class knows that you're uploading the image via unit testing environment.