コード例 #1
0
 internal static MultipartData BuildMultipartData(Photo photo)
 {
     MultipartData data = new MultipartData ();
                 data.Add (new MultipartData.Parameter ("image", photo.Filepath,
                                         MultipartData.Parameter.ParamType.File));
                 data.Add (new MultipartData.Parameter ("title", photo.Title,
                                         MultipartData.Parameter.ParamType.Field));
                 data.Add (new MultipartData.Parameter ("access_type", Photo.ToString (photo.AccessLevel),
                                         MultipartData.Parameter.ParamType.Field));
                 data.Add (new MultipartData.Parameter ("disable_comments",
                                         photo.DisableComments.ToString ().ToLower (),
                                         MultipartData.Parameter.ParamType.Field));
                 data.Add (new MultipartData.Parameter ("hide_orignal",
                                         photo.HideOriginal.ToString ().ToLower (),
                                         MultipartData.Parameter.ParamType.Field));
                 data.Add (new MultipartData.Parameter ("xxx",
                                         photo.AdultContent.ToString ().ToLower (),
                                         MultipartData.Parameter.ParamType.Field));
                 return data;
 }
コード例 #2
0
        internal string PostMultipart(string uri, MultipartData data, bool async)
        {
            const string boundary = "AaB03x";

                        HttpWebRequest request = CreateRequest (uri);
                        request.Method = "POST";
                        request.ContentType = "multipart/form-data; boundary=" + boundary;
                        Stream content = data.Form (boundary);
                        request.ContentLength = content.Length;
                        request.AllowWriteStreamBuffering = false;
                        Stream request_stream = request.GetRequestStream ();

                        byte[] buffer = new byte[1024];
                        int read;
                        long readBytes = 0;

                        while((read = content.Read(buffer, 0, buffer.Length)) > 0) {
                                request_stream.Write(buffer, 0, read);
                                readBytes += read;
                                if (async) {
                                        OnRequestProgressChanged (
                                                        new RequestProgressChangedEventArgs (
                                                                RequestMethod.PostMultipart,
                                                                readBytes,
                                                                content.Length));
                                }
                        }
                        if (async)
                                OnRequestCompleted (new RequestCompletedEventArgs (
                                                        RequestMethod.PostMultipart));

                        request_stream.Close ();
                        content.Close ();

                        return WebHelper.GetResponseString (request);
        }
コード例 #3
0
 internal string PostMultipart(string uri, MultipartData data)
 {
     return PostMultipart (uri, data, false);
 }