Win10 uwp SMMs Picture bed

Source: Internet
Author: User
Tags creative commons attribution

This article, how to use SMMs map to upload pictures, use to Win10 uwp post file, because I am slag, if this article is wrong, please and I said, in this article comment, or send me email [email protected], please do not make bad remarks

Find a good bed, sm.ms.

Can simply use post to upload files, I have made a tool, you can upload pictures, use only need

Incoming file42E32CBE4C4531C77E4DAB5853D7D4B9 SMMs. Model. ImageShackImageShack = new ImageShack () {file=file,};Upload Complete event, where STR is SM. MsReturn, generally JSON//reminder is an example, can be modified according to specific, note to synchronize Coreapplication. MainView. CoreWindow. Dispatcher. RunAsyncImageShack. Onuploadedeventhandler+ = (sender, str) = = Reminder = str. Replace("\\/","/");Upload ImageShack. UpLoad();

I'm going to tell you what I found out.

Error in httpclient post parameter

Convert from "Windows.Web.Http.HttpStringContent" to "System.Net.Http.HttpContent"

Reason

With the System.Net.Http.HttpClient fact that httpstringcontent can be seen in error, not System.Net.Http

Method is simple, we need to change

Use

           Windows.Web.Http.HttpClient webHttpClient=                new Windows.Web.Http.HttpClient();           Windows.Web.Http.HttpStringContent httpString=                new HttpStringContent("http://blog.csdn.net/lindexi_gd");            await webHttpClient.PostAsync(new Uri(url), httpString);
Win10 UWP Post Upload file

We can use Httpmultipartformdatacontent to upload
Where we need to go from file to stream, open storagefile, convert it httpstreamcontent

        var fileContent = new HttpStreamContent(await File.OpenAsync(FileAccessMode.Read));

Then we want to FILECONTENT.HEADERS.ADD ("Content-type", "Application/octet-stream");

We can add httpmultipartformdatacontent to filecontent and see sm.ms.

Parameter name type whether you must Description
Smfile File Is Name of the form. Upload images to use
Ssl Bool Whether Whether to use HTTPS output, default off
Format String Whether The format of the output. The optional values are JSON, XML. The default is JSON
Domain Int Whether Picture domain name. Options available

We'll change Add(IHttpContent content, System.String name, System.String fileName); the name "Smfile".

httpMultipartFormDataContent.Add(fileContent, "smfile", File.Name);

Useawait webHttpClient.PostAsync(new Uri(url), httpMultipartFormDataContent);

Because I need to get an upload image

varawait webHttpClient.PostAsync(new Uri(url), httpMultipartFormDataContent);            ResponseString = str.Content.ToString();            OnUploadedEventHandler?.Invoke(this,ResponseString);
All code

Https://github.com/lindexi/Imageshack/tree/master/smms


This work is licensed under the Creative Commons Attribution-NonCommercial use-Share 4.0 International license agreement in the same way. Welcome to reprint, use, republish, but be sure to keep the article Attribution Lindesi (including Link: http://blog.csdn.net/lindexi_gd), not for commercial purposes, based on the modified works of this article must be issued with the same license. If you have any questions, please contact me.

Win10 uwp SMMs Picture bed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.