Note that there are some explanatory texts on larger screens.

plurals
  1. POWin Phone 8 / Asp .Net Web API Image Upload
    text
    copied!<p>The following code responsible for uploading images:</p> <pre><code>[HttpPost] public async Task&lt;HttpResponseMessage&gt; Upload() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var streamProvider = new MultipartMemoryStreamProvider(); Cloudinary cloudinary = new Cloudinary(ConfigurationManager.AppSettings.Get("CLOUDINARY_URL")); return await Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =&gt; { if (t.IsFaulted || t.IsCanceled) throw new HttpResponseException(HttpStatusCode.InternalServerError); var content = streamProvider.Contents.FirstOrDefault().ReadAsStreamAsync(); ImageUploadParams uploadParams = new ImageUploadParams() { File = new CloudinaryDotNet.Actions.FileDescription(Guid.NewGuid().ToString(), content.Result) }; ImageUploadResult uploadResult = cloudinary.Upload(uploadParams); string url = cloudinary.Api.UrlImgUp.BuildUrl(String.Format("{0}.{1}", uploadResult.PublicId, uploadResult.Format)); return Request.CreateResponse&lt;MediaModel&gt;(HttpStatusCode.Created, new MediaModel { URL = url }); }); } </code></pre> <p>It works via jquery post request. However, in win phone 8 application, the following code does not seem to make a request to the api:</p> <pre><code>public async Task&lt;string&gt; UploadImage(byte[] image) { var client = new HttpClient(); var content = new MultipartFormDataContent(); var imageContent = new ByteArrayContent(image); imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg"); content.Add(imageContent, "image", string.Format("{0}.jpg", Guid.NewGuid().ToString())); return await client.PostAsync(baseURL + "image/Upload", content).Result.Content.ReadAsStringAsync().ContinueWith(t =&gt; { return t.Result; }); } </code></pre> <p>What is the problem here? I hope someone could show me the proper use of httpclient.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload