diff --git a/includes/media.pages.inc b/includes/media.pages.inc
index 7aee3ee..98bfb73 100644
--- a/includes/media.pages.inc
+++ b/includes/media.pages.inc
@@ -250,12 +250,17 @@ function media_add_upload_submit($form, &$form_state) {
   $destination = file_stream_wrapper_uri_normalize($scheme . $directory . $file->filename);
 
   // Save the uploaded file to the permanent location.
+  $file_original = $file;
   $file = file_move($file, $destination, FILE_EXISTS_RENAME);
 
   if ($file) {
     drupal_set_message(t('The file @name was uploaded', array('@name' => $file->filename)));
   }
   else {
+    watchdog('media', 'Unable to move file @name to its destination.', array('@name' => $file->filename));
+    // Remove the file from database. Otherwise uploading the same file later
+    // again will fail with an "unexpected error".
+    file_delete($file_original);
     drupal_set_message(t('An error occurred and no file was uploaded.'), 'error');
     return;
   }
