diff --git a/lib/file.c b/lib/file.c
index 4a064a065c81d20e1c69388ffc0c7a8b91090d5a..8f47a19e68f9732554ba8b42e8229bbf7382e72c 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -218,7 +218,12 @@ static CURLcode file_upload(struct connectdata *conn)
     Curl_pgrsSetUploadSize(data, data->set.infilesize);
 
   while (res == CURLE_OK) {
-    nread = Curl_fillreadbuffer(conn, BUFSIZE);
+    int readcount;
+    res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount);
+    if(res)
+      return res;
+
+    nread = (size_t)readcount;
 
     if (nread <= 0)
       break;
diff --git a/lib/transfer.c b/lib/transfer.c
index 9ce78c552975705a89e0b962b637a4487a094136..1da2cc9c10cf94d060e9b4f078e937e0100eee59 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -125,8 +125,9 @@ static struct timeval notimeout={0,0};
  * This function will call the read callback to fill our buffer with data
  * to upload.
  */
-int Curl_fillreadbuffer(struct connectdata *conn, int bytes)
+CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
 {
+  struct SessionHandle *data = conn->data;
   int buffersize = bytes;
   int nread;
 
@@ -139,6 +140,11 @@ int Curl_fillreadbuffer(struct connectdata *conn, int bytes)
   nread = conn->fread(conn->upload_fromhere, 1,
                       buffersize, conn->fread_in);
 
+  if(nread == CURL_READFUNC_ABORT) {
+    failf(data, "operation aborted by callback\n");
+    return CURLE_ABORTED_BY_CALLBACK;
+  }
+
   if(!conn->bits.forbidchunk && conn->bits.upload_chunky) {
     /* if chunked Transfer-Encoding */
     char hexbuffer[11];
@@ -161,7 +167,10 @@ int Curl_fillreadbuffer(struct connectdata *conn, int bytes)
 
     nread+=2; /* for the added CRLF */
   }
-  return nread;
+
+  *nreadp = nread;
+
+  return CURLE_OK;
 }
 
 /*
@@ -1131,7 +1140,9 @@ CURLcode Curl_readwrite(struct connectdata *conn,
               break;
             }
 
-            nread = Curl_fillreadbuffer(conn, BUFSIZE);
+            result = Curl_fillreadbuffer(conn, BUFSIZE, &nread);
+            if(result)
+              return result;
           }
           else
             nread = 0; /* we're done uploading/reading */
diff --git a/lib/transfer.h b/lib/transfer.h
index ddcca06c15ae76e5864e404d2906a23e8a964076..4ebf07532297420f09e561c580de1a680b7e3925 100644
--- a/lib/transfer.h
+++ b/lib/transfer.h
@@ -35,7 +35,7 @@ void Curl_single_fdset(struct connectdata *conn,
                        int *max_fd);
 CURLcode Curl_readwrite_init(struct connectdata *conn);
 
-int Curl_fillreadbuffer(struct connectdata *conn, int bytes);
+CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp);
 
 /* This sets up a forthcoming transfer */
 CURLcode