Exemplo n.º 1
0
        public string callUploadAttachment(string filename, string user_email)
        {
            string result      = "";
            string title       = "";
            string description = "";
            string type        = "image";
            string image_data  = "medium";
            string object_id   = genGuid();
            string post_id     = "";

            try
            {
                MR_attachments_upload _attachment = attachments_upload(session_token, group_id, filename, title, description, type, image_data, object_id, post_id);
                result = _attachment.object_id;
            }
            catch (Exception err)
            {
                log.Error("upload error: " + err.Message);
                Console.WriteLine("Error: " + err.Message);
            }
            return(result);
        }
Exemplo n.º 2
0
        public MR_attachments_upload attachments_upload(string session_token, string group_id, string fileName,
                                                        string title, string description, string type, string image_meta,
                                                        string object_id, string post_id)
        {
            MR_attachments_upload _ret = null;

            try
            {
                string _url = "https://develop.waveface.com:443/v3" + "/pio_attachments/upload";

                string _mimeType = FileUtility.GetMimeType(new FileInfo(fileName));

                byte[] _data = FileUtility.ConvertFileToByteArray(fileName);

                Dictionary <string, object> _dic = new Dictionary <string, object>();
                _dic.Add("apikey", APIKEY);
                _dic.Add("session_token", session_token);
                _dic.Add("group_id", group_id);
                _dic.Add("file_name", "image_001.jpg");
                _dic.Add("title", title);
                //
                DateTime fileCreatedDate = File.GetCreationTime(fileName);
                string   _date           = fileCreatedDate.ToString(@"yyyy-MM-ddTHH\:mm\:ssZ");
                _dic.Add("file_create_time", _date);

                //if (description == string.Empty)
                //   description = title;

                _dic.Add("description", description);
                _dic.Add("type", type);

                if (type == "image")
                {
                    _dic.Add("image_meta", image_meta);
                }

                if (object_id != string.Empty)
                {
                    _dic.Add("object_id", object_id);
                }

                if (post_id != string.Empty)
                {
                    _dic.Add("post_id", post_id);
                }

                _dic.Add("file", _data);

                string _userAgent = "Windows";

                string _fileName = new FileInfo(fileName).Name;

                HttpWebResponse _webResponse = MultipartFormDataPostHelper.MultipartFormDataPost(_url, _userAgent, _dic,
                                                                                                 _fileName, _mimeType);


                // Process response
                StreamReader _responseReader = new StreamReader(_webResponse.GetResponseStream());
                string       _r = _responseReader.ReadToEnd();
                _webResponse.Close();

                _ret = JsonConvert.DeserializeObject <MR_attachments_upload>(_r);
            }
            catch (WebException _e)
            {
                //NLogUtility.WebException(s_logger, _e, "attachments_upload", true);

                if (_e.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse res = (HttpWebResponse)_e.Response;
                    log.Error("upload attachments error response: " + res);
                }
            }
            catch (Exception _e)
            {
            }

            return(_ret);
        }