1
votes

I'm sending a file by my cordova app and send a blob object When I get it with server side, I try to upload it via media_handle_upload function but I can't this error :

sorry this file type is not permitted for security reasons

I think wordpress doesn't allo blob object, but how to convert this object to upload my file with media_handle_upload ?

Thanks

1

1 Answers

0
votes

Finally I proceeded another way

When I receive my blob file in php, I use this to upload the file in a temporary directory :

move_uploaded_file($tmp_name, $destination);

Then I download the file (with url) with wordpress like that :

$file = array();
$file['name'] =basename($temp_url);
$file['tmp_name'] = download_url($temp_url);

Then I upload the file into wordpress as attachment with :

$attachment_id = media_handle_sideload($file, $post_id);

Don't forget to delete the temporary file with : unlink($toDelete); (path URL)