I have uploaded an image to a local folder using the below code using ajax and php after some cropping and image zooming functionality.
After this function, the cropped image is sanded to a local folder called upload. But the image is processed with base64 encode and decode model. I want to send the cropped/saved image to an api with out base64 data all I want is send the image as form data/file.
The code that used for image upload is image data is sent as form data and is base64 encoded format
url = URL.createObjectURL(blob);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function(){
var base64data = reader.result;
formData.append('image', base64data);
$.ajax({
url:'<?php echo get_template_directory_uri(); ?>/upload.php?>',
method:'POST',
data:formData
and in upload.php
if(isset($_REQUEST['image'])) {
$data = $_REQUEST['image'];
$image_array_1 = explode(";", $data);
$image_array_2 = explode(",", $image_array_1[1]);
$data = base64_decode($image_array_2[1]);
$image_name = 'upload/' . time() . '.png';
file_put_contents($image_name, $data);
}
i want to take this image from folder and send this data to an api as file/multipart formdata with out encryption/decrypted format
Please help me to solve this. Thank you in advance.