\yii\web\UploadedFile::getInstance not working File Update in REST API yii2

1.6k Views Asked by At

Hi Im using REST API in yii 2 \yii\web\UploadedFile::getInstance is not getting file in my function.for debugging purpose I tried with $_FILES['asset'] its printing with values.but not getting file instance using \yii\web\UploadedFile::getInstance

$updateFile = $_FILES['asset']; //Printing values
$model->asset = \yii\web\UploadedFile::getInstance($model, 'asset'); //Not printing,its empty

What is the issues,I couldn't validate If i process the file with $_FILES.Any help would be grateful!! Thanks in Advance

2

There are 2 best solutions below

1
On

Try this:

getInstanceByName('asset');
2
On

Your data should come like $_FILES['Your_Model_Name']['asset'] if you want to use UploadedFile::getInstance method. Try this, it will work.

$updateFile = $_FILES['User']['asset']; //Printing values
$model->asset = \yii\web\UploadedFile::getInstance($model, 'asset'); // Not printing, it's empty