private static void PrepareUpload(RestBase request, string path)
        {
            //account/update_profile_image.json?image=[FILE_PATH]&include_entities=1
            var startIndex = path.IndexOf("?image_path=", StringComparison.Ordinal) + 12;
            var endIndex   = path.IndexOf("&", StringComparison.Ordinal);
            var uri        = path.Substring(startIndex, endIndex - startIndex);

            path           = path.Replace(string.Format("image_path={0}&", uri), "");
            request.Path   = path;
            request.Method = WebMethod.Post;
#if !WINRT
            request.AddFile("image", Path.GetFileName(Uri.UnescapeDataString(uri)), Path.GetFullPath(Uri.UnescapeDataString(uri)), "multipart/form-data");
#else
            var fullPath = Uri.UnescapeDataString(uri);
            if (!System.IO.Path.IsPathRooted(fullPath))                             //Best guess at how to create a 'full' path on WinRT where file access is restricted and all paths should be passed as 'full' versions anyway.
            {
                fullPath = System.IO.Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, uri);
            }
            request.AddFile("image", Path.GetFileName(Uri.UnescapeDataString(uri)), fullPath, "multipart/form-data");
#endif
        }
        private static void PrepareUpload(RestBase request, string path)
        {
            //account/update_profile_image.json?image=[FILE_PATH]&include_entities=1
            var startIndex = path.IndexOf("?image_path=", StringComparison.Ordinal) + 12;
            var endIndex   = path.LastIndexOf("&", StringComparison.Ordinal);
            var uri        = path.Substring(startIndex, endIndex - startIndex);

            path           = path.Replace(string.Format("image_path={0}&", uri), "");
            request.Path   = path;
            request.Method = WebMethod.Post;
            request.AddFile("image", Path.GetFileName(Uri.UnescapeDataString(uri)), Path.GetFullPath(Uri.UnescapeDataString(uri)), "multipart/form-data");
        }
Beispiel #3
0
        private static void PrepareUpload(RestBase request, string path)
        {
            var startIndex = path.IndexOf("?status=", StringComparison.Ordinal) + 8;
            var endIndex   = path.IndexOf("&pic=", StringComparison.Ordinal);

            request.Method = WebMethod.Post;

            string status = path.Substring(startIndex, endIndex - startIndex);

            request.AddField("status", status);

            // https://upload.api.weibo.com/2/statuses/upload.json
            startIndex = path.IndexOf("&pic=", StringComparison.Ordinal) + 5;
            endIndex   = path.Trim().Length;

            var uri = path.Substring(startIndex, endIndex - startIndex);

            path         = path.Remove(path.IndexOf("?status="));
            request.Path = path;

            var file = new FileStream(Uri.UnescapeDataString(uri), FileMode.Open);

            request.AddFile("pic", Path.GetFileName(Uri.UnescapeDataString(uri)), file, "image/jpeg");
        }