5 months ago

upload pdf file base64

Posted 5 months ago by atfinho

I'm trying to upload a pdf file encoded in base64

the file got uploaded but it's not accessible " PDF document is damaged"

this is my code :

 public function handleUploadPdf(Request $request){

    $image = $request->input('image');  // your base64 encoded
    $image = str_replace('data:application/pdf;base64,', '', $image);
    $image = str_replace(' ', '+', $image);
    $imageName = str_random(10).'.'.'pdf';
    \File::put(public_path(). '/images/' . $imageName, base64_decode($image));

    return response()->json(['status'=>200]);


what is causing this issue ? thank you in advance

Please sign in or create an account to participate in this conversation.