case : i am trying to upload webrecord audio to wordress post . so i have form with post id and input type file "audio_upload"

below is my code snippet

 $audio_meta_value = media_handle_upload( 'audio_upload', $pid);

above code works fine.

Issue: i have added webrecord to my form at bottom , i am able to save audio via below code using ajax , but i am stuck with adding that audio to my post that .

Any possible solution ? 1: Is there any wordpress function that accepts blob data / base64 encode instead of $_FILES to save attachment.

2: can i do append blob data to file input in form so my previous flow will works

code to save audio via ajax

  var data = new FormData();
  data.append('file', blob);

    url: "server.php",
    type: 'POST',
    data: data,
    contentType: false,
    processData: false,
    success: function(data) {
      // Sent to Server
}, "blob");


  // $audio = file_get_contents($_FILES['file']['tmp_name']);
  $audio = $_FILES['file']['tmp_name'];
  $newpath = "soundrec/uploaded_audio".time().".wav";
  echo $newpath;
  • Did you manage to get this working? I'm running into a similar issue trying to get media_handle_upload() working with a blob type.
    – Swen
    Commented Jan 5, 2018 at 17:16
  • I'm also having issues with this - grateful any help!
    – Seano
    Commented Feb 6, 2018 at 19:20

1 Answer 1


you can do that with the function wp_handle_sideload https://developer.wordpress.org/reference/functions/wp_handle_sideload/

Steps to make this :

  1. create a temporary file with the content you need
  2. pass this filename to function wp_handle_sideload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.