本文整理汇总了C#中System.Net.Http.MultipartFormDataContent.ReadAsByteArrayAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MultipartFormDataContent.ReadAsByteArrayAsync方法的具体用法?C# MultipartFormDataContent.ReadAsByteArrayAsync怎么用?C# MultipartFormDataContent.ReadAsByteArrayAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.MultipartFormDataContent
的用法示例。
在下文中一共展示了MultipartFormDataContent.ReadAsByteArrayAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload
/// <summary>
/// Synchronously uploads the file to Uploadcare.
///
/// The calling thread will be busy until the upload is finished.
/// </summary>
/// <returns> An Uploadcare file </returns>
/// <exception cref="UploadFailureException"> </exception>
public UploadcareFile Upload(bool? store = null)
{
var url = Urls.UploadBase();
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
try
{
var boundary = "Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
using (var content = new MultipartFormDataContent(boundary))
{
content.Add(new StringContent(_client.PublicKey), "UPLOADCARE_PUB_KEY");
if (store != null)
if (store.Value)
content.Add(new StringContent("1"), "UPLOADCARE_STORE");
else
content.Add(new StringContent("0"), "UPLOADCARE_STORE");
else
content.Add(new StringContent("auto"), "UPLOADCARE_STORE");
if (_file != null)
content.Add(new StreamContent(File.OpenRead(_file.FullName)), "file", _file.Name);
else
content.Add(new ByteArrayContent(_bytes), "file", _fileName);
var buffer = content.ReadAsByteArrayAsync().Result;
using (var reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
var fileId = _client.GetRequestHelper().ExecuteQuery(request, false, new UploadBaseData()).File;
return _client.GetFile(fileId);
}
}
catch (Exception)
{
throw new UploadFailureException();
}
}