Parse uploading picture from form
Hi,
I'm working on a backoffice for an application that runs with Parse.com for it's database. So I'm using it in Laravel to make the modifications. I'm kind of stuck when trying to upload a picture from a forms into the parse database since apparently storing files in parse is ok.
public function store(Request $request) {
$id = $request->input('redirect_id');
try {
$file = null;
if ($request->hasFile('pictures')) {
$upload = $request->file('pictures');
$file = ParseFile::createFromFile($upload->getRealPath().'/'.$upload->getClientOriginalName(), $upload->getClientOriginalName(), $upload->getClientMimeType());
}
$media = new ParseObject('Media');
$media->set('place_id', $id);
$media->set('media_data', $file);
$media->save();
} catch(ParseException $ex) {
dd($ex->getMessage());
}
return redirect()->route('place.edit', $id);
}
And I'm getting this error :
file_get_contents(/tmp/1920x1200-3.png): failed to open stream: No such file or directory
And the createFromFile method from Parse :
public static function createFromFile($path, $name, $mimeType = null)
{
$contents = file_get_contents($path, 'rb');
return static::createFromData($contents, $name, $mimeType);
}
So, I don't know why the file_get_contents can't reach the picture that has been uploaded maybe he can't access from the temp directory but it's weird.
Maybe I need to use the createFromData method
public static function createFromData($contents, $name, $mimeType = null)
{
$file = new self();
$file->name = $name;
$file->mimeType = $mimeType;
$file->data = $contents;
return $file;
}
But what should I do to retrieve the content of the picture uploaded since the file_get_contents is not working ? Should I move the picture somewhere else so it to be accessible ?
Thanks in advance for your answer !
Please or to participate in this conversation.