#Saving Base64 encoded Image in Storage

6 messages · Page 1 of 1 (latest)

quiet badger
#

I currently have an API running to implement Signotec Signing capabilities. They have this code:

                    if (value.file !== undefined) {
                        document.getElementById("Signature_0").src = "data:image/png;base64," + value.file;
                    }

to set the img element with the value.file.

I would like to save that file as png on my Server, i would use this code:

// Retrieve the image data from the JavaScript file
        $imageData = $request->input('file');

        // Decode the Base64-encoded data
        $decodedImage = base64_decode($imageData);

        // Save the image file to storage
        $path = Storage::put('public/signatures/signature.png', $decodedImage);

        // Return the path to the saved image
        return response()->json(['path' => $path]);

and then save the $path into my purchase database. Is this correct? And how would I do this correctly?

limber coral
#

Why would you send a file from the frontend as a base64 image? Why not leverage actual file uploads?

quiet badger
pastel thorn
#

Here:

if (value.file !== undefined) {
    document.getElementById("Signature_0").src = "data:image/png;base64," + value.file;
}

Just send the file instead?

limber coral
#

Yeah, that's exactly my thought, you have a file, but you're sending it as a base64 encoded string shrug Whatever library you're using doesn't matter, you're the one sending base64