나는 그 파일을 어떤 관계로 저장한다고 가정한다.
for ex: profile picture etc.. (so in this case you try to attach that file to user)
이렇게 예를 들자면.
you mentioned you are successfully converting to jpeg
but for example I just added rough code for that as well.
// we assume you post `base64` string in `img`
$img = post('img');
$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$imageData = base64_decode($img);
// we got raw data of file now we can convert this row data to file in dist and add that to `File` model
$file = (new \System\Models\File)->fromData($imageData, 'your_preferred_name.jpeg');
// attach that $file to Model
$yourModel->avatar = $file;
$yourModel->save();
OR if you don't save that file with relation you can now point that file with $file->id
and find it next time or save it for later use.
// next time
// $file->id
$yourFile = \System\Models\File::find($file->id);
이제 파일입니다 base64
인코딩 된 파일을 모바일 앱에서 요청을 수신 할 때 user model
내부
당신은
public $attachOne = [
'avatar' => 'System\Models\File'
];
지금의 관계를 정의 할 수 있습니다 다음 번에 해당 파일이 필요하면 직접 파일을 사용할 수 있습니다.
$imageData = $yourModel->avatar->getContents();
$imageBase64Data = base64_encode($imageData);
// $imageBase64Data <- send to mobile if needed.
불명확 한 점이 있으면 의견을 말하십시오.
지원해 주셔서 감사합니다. – Crazy
나는 이것이 오류입니다 : 비 객체의 속성을 얻으려고하면이 부분에 있다고 생각합니다 : // 해당 $ 파일을 Model $ yourModel-> avatar = $ file; – Crazy
파일 객체가 생성되지 않은 것처럼 보이고, 거기에'$ imageData'를 가지고 좀 더 디버그 할 수 있습니다. –