public Read ( Blob blob, byte buffer, int offset, int count ) : int | ||
blob | Blob | |
buffer | byte | |
offset | int | |
count | int | |
return | int |
private void _beginRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest req = (HttpWebRequest)asynchronousResult.AsyncState; try { using (Stream reqStream = req.EndGetRequestStream(asynchronousResult)) { if (_multipart) { reqStream.Write(_multipartHeader, 0, _multipartHeader.Length); } // stream the file if (_blob != null) { Blob blob = (Blob)_blob; FileReader fileReader = new FileReader(); int bytesRead = 0; long bytesLoaded = 0; byte[] buffer = new byte[1024 * 200]; while ((bytesRead = fileReader.Read(blob, buffer, 0, buffer.Length)) != 0) { reqStream.Write(buffer, 0, bytesRead); reqStream.Flush(); // will block until data is sent bytesLoaded += bytesRead; _fireUploadProgress(bytesLoaded, blob.size); } } // append multipart file footer if (_multipart) { reqStream.Write(_multipartFooter, 0, _multipartFooter.Length); } } } catch (WebException ex) { if (ex.Status != WebExceptionStatus.RequestCanceled) // if request was not aborted { _syncContext.Post(delegate { Error(this, null); }, this); } } catch (Exception ex) { _syncContext.Post(delegate { Error(this, null); }, this); } try { req.BeginGetResponse(new AsyncCallback(_responseCallback), req); } catch (WebException ex) { if (ex.Status != WebExceptionStatus.RequestCanceled) // if request was not aborted { _syncContext.Post(delegate { Error(this, null); }, this); } } catch (Exception ex) { _syncContext.Post(delegate { Error(this, null); }, this); } }
private void _beginRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest req = (HttpWebRequest)asynchronousResult.AsyncState; try { using (Stream reqStream = req.EndGetRequestStream(asynchronousResult)) { if (_multipart) { reqStream.Write(_multipartHeader, 0, _multipartHeader.Length); } // stream the file if (_blob != null) { Blob blob = (Blob)_blob; FileReader fileReader = new FileReader(); int bytesRead = 0; long bytesLoaded = 0; byte[] buffer = new byte[1024 * 200]; while ((bytesRead = fileReader.Read(blob, buffer, 0, buffer.Length)) != 0) { reqStream.Write(buffer, 0, bytesRead); reqStream.Flush(); // will block until data is sent bytesLoaded += bytesRead; _fireUploadProgress(bytesLoaded, blob.size); } } // append multipart file footer if (_multipart) { reqStream.Write(_multipartFooter, 0, _multipartFooter.Length); } } } catch (WebException ex) { if (ex.Status != WebExceptionStatus.RequestCanceled) // if request was not aborted { _syncContext.Post(delegate { Error(this, null); }, this); } } catch (Exception ex) { _syncContext.Post(delegate { Error(this, null); }, this); } try { req.BeginGetResponse(new AsyncCallback(_responseCallback), req); } catch (WebException ex) { if (ex.Status != WebExceptionStatus.RequestCanceled) // if request was not aborted { _syncContext.Post(delegate { Error(this, null); }, this); } } catch (Exception ex) { _syncContext.Post(delegate { Error(this, null); }, this); } }