public async Task <ActionResult <ServerFile> > PostServerFile(IList <IFormFile> files)
        {
            ServerFile serverFile = JsonConvert.DeserializeObject <ServerFile>(HttpContext.Request.Form["serverFile"]);

            if (files.Count == 0)
            {
                return(BadRequest());
            }

            serverFile.Name = files[0].FileName;
            FileBody fileBody;

            using (var streamReader = new MemoryStream()) {
                IFormFile file = files[0];
                if (file.ContentType != "text/plain" &&
                    file.ContentType != "text/html" &&
                    file.ContentType != "text/richtext" &&
                    file.ContentType != "text/xml")
                {
                    files[0].OpenReadStream().CopyTo(streamReader);
                }
                fileBody = new FileBody()
                {
                    Body = streamReader.ToArray(), ContentType = file.ContentType
                };
            }
            serverFile.FileBody = fileBody;
            serverFile.Size     = files[0].Length;

            _context.Files.Add(serverFile);
            await _context.SaveChangesAsync();

            serverFile.FileBody = null;
            return(CreatedAtAction("GetServerFile", new { id = serverFile.Id }, serverFile));
        }
Esempio n. 2
0
        public void HttpPostWithFilesAndParameters3()
        {
            // this method sends a file and checks for the number of bytes recieved
            HttpClient client     = new HttpClient();
            string     url        = "http://www.fiddler2.com/sandbox/FileForm.asp";
            HttpPost   postMethod = new HttpPost(new Uri(url));

            MultipartEntity multipartEntity = new MultipartEntity();

            postMethod.Entity = multipartEntity;

            string fileName = "small-text.txt";

            StringBody stringBody1 = new StringBody(Encoding.ASCII, "1", "1_");

            multipartEntity.AddBody(stringBody1);

            FileInfo fi        = ResourceManager.GetResourceFileInfo(fileName);
            FileBody fileBody1 = new FileBody("fileentry", fileName, fi, "text/plain");

            multipartEntity.AddBody(fileBody1);

            StringBody stringBody2 = new StringBody(Encoding.ASCII, "_charset_", "windows-1252");

            multipartEntity.AddBody(stringBody2);

            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);

            Assert.AreEqual(url, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
Esempio n. 3
0
        public async Task <IActionResult> PutFileBody(Guid id, FileBody fileBody)
        {
            if (id != fileBody.ServerFileId)
            {
                return(BadRequest());
            }

            _context.Entry(fileBody).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FileBodyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public static string get_9kw_api_upload(string data)
        {
            HttpClient client     = new HttpClient();
            HttpPost   postMethod = new HttpPost(new Uri("http://www.9kw.eu/index.cgi"));

            MultipartEntity multipartEntity = new MultipartEntity();

            postMethod.Entity = multipartEntity;

            StringBody stringBody = new StringBody(Encoding.UTF8, "apikey", _9kw.apikey);

            multipartEntity.AddBody(stringBody);

            StringBody stringBody3 = new StringBody(Encoding.UTF8, "source", "csapi");

            multipartEntity.AddBody(stringBody3);

            StringBody stringBody2 = new StringBody(Encoding.UTF8, "action", "usercaptchaupload");

            multipartEntity.AddBody(stringBody2);

            FileInfo fileInfo = new FileInfo(@data);
            FileBody fileBody = new FileBody("file-upload-01", data, fileInfo);

            multipartEntity.AddBody(fileBody);

            HttpResponse response = client.Execute(postMethod);

            return(EntityUtils.ToString(response.Entity));
        }
Esempio n. 5
0
        public void HttpPostWithFilesAndParameters()
        {
            // this method sends an empty file (or no file :)
            HttpClient client     = new HttpClient();
            HttpPost   postMethod = new HttpPost(new Uri(Constants.HTTP_MULTIPART_POST_200));

            MultipartEntity multipartEntity = new MultipartEntity();
            StringBody      stringBody1     = new StringBody(Encoding.ASCII, "param1", "value1");

            multipartEntity.AddBody(stringBody1);
            StringBody stringBody2 = new StringBody(Encoding.ASCII, "param2", "!#$^&*((<>");

            multipartEntity.AddBody(stringBody2);
            FileBody fileBody1 = new FileBody("photo", "me.file", null);

            multipartEntity.AddBody(fileBody1);
            postMethod.Entity = multipartEntity;
            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string      responseString = EntityUtils.ToString(response.Entity);
            MessageData md             = new MessageData();

            md.PostParameters.Add(new NameValuePair("param1", "value1"));
            md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>"));
            md.Files.Add(new NameValuePair("me.file", "0"));
            Assert.AreEqual(md.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_MULTIPART_POST_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
Esempio n. 6
0
        public void SendFileMsgTest()
        {
            var mediaId = m_appClient.UploadFile(AppClient.FileTypeFile, FileName, FilePath);
            var body    = new FileBody(mediaId);
            var msg     = new Message(ToUsers, Message.MessageTypeFile, body);

            m_appClient.SendMsg(msg);
        }
Esempio n. 7
0
        public void SaveFileDataTest()
        {
            // TODO: add unit test for the method 'SaveFileData'
            string   myAppId = null; // TODO: replace null with proper value
            FileBody fileObj = null; // TODO: replace null with proper value

            var response = instance.SaveFileData(myAppId, fileObj);

            Assert.IsInstanceOf <string> (response, "response is string");
        }
Esempio n. 8
0
        private string findItem(string title)
        {
            int startIndex = FileBody.IndexOf("<" + title + ">");
            int endIndex   = FileBody.IndexOf("</" + title + ">");

            if (startIndex < 0 || endIndex < 0)
            {
                return("");
            }
            else
            {
                startIndex += +title.Length + 2;
                return(FileBody.Substring(startIndex, endIndex - startIndex));
            }
        }
        public void ConvertToFile(string savePath)
        {
            try
            {
                savePath.DeleteSigleFile();

                byte[] fileByte = Convert.FromBase64String(FileBody.Trim().Replace(" ", "+"));

                using (FileStream fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write))
                {
                    fileStream.Write(fileByte, 0, fileByte.Length);
                    fileStream.Close();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 10
0
        public byte[] ToByteArray()
        {
            if (!string.IsNullOrWhiteSpace(FileBody))
            {
                var pos = FileBody.IndexOf("base64", StringComparison.Ordinal);
                if (pos > 0)
                {
                    var fileBody = FileBody.Substring(pos + "base64,".Length);

                    try
                    {
                        var data = Convert.FromBase64String(fileBody);
                        return(data);
                    }
                    catch (Exception) { }
                }
            }
            return(null);
        }
Esempio n. 11
0
        public async Task <ActionResult <FileBody> > PostFileBody(FileBody fileBody)
        {
            _context.FileBodies.Add(fileBody);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (FileBodyExists(fileBody.ServerFileId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetFileBody", new { id = fileBody.ServerFileId }, fileBody));
        }
Esempio n. 12
0
        public string postFile(string session, string fileName)
        {
            int    GOOD_RETURN_CODE = 200;
            string subIdLocal       = "";

            FileStream imageFile = File.OpenRead(fileName);

            CodeScales.Http.HttpClient httpClient = new CodeScales.Http.HttpClient();
            HttpPost httpPost = new HttpPost(new Uri(url + "/api/upload/"));


            JsonObject      jsonObject = getUploadJSON(session);
            MultipartEntity reqEntity  = new MultipartEntity();

            StringBody stringBody = new StringBody(Encoding.UTF8, "request-json", jsonObject.ToString());

            reqEntity.AddBody(stringBody);
            FileInfo fileInfo = new FileInfo(fileName);
            FileBody fileBody = new FileBody("file", fileName, fileInfo);

            reqEntity.AddBody(fileBody);

            httpPost.Entity = reqEntity;
            HttpResponse response = httpClient.Execute(httpPost);

            String result = "";

            int respCode = response.ResponseCode;

            if (respCode == GOOD_RETURN_CODE)
            {
                HttpEntity entity  = response.Entity;
                String     content = EntityUtils.ToString(entity);
                string     success = jsonGetValue(content, "status");
                subIdLocal = jsonGetValue(content, "subid");
                string hash = jsonGetValue(content, "hash");
            }

            return(subIdLocal);
        }
        internal TranslationUnit GetTranslationUnit(UIDataString key)
        {
            switch (key.Type)
            {
            case LocalizableStringType.Category:
                return(Localizations.Categories.TranslationUnits.FirstOrDefault(tu => tu.English == key.SourceUIString));

            case LocalizableStringType.SectionHeading:
                return(Localizations.Groups.FirstOrDefault(g => g.Id == FileBody.GetSectionId(key))?.TranslationUnits.Single());

            case LocalizableStringType.Question:
                return(Localizations.FindQuestionGroup(key)?.TranslationUnits.Single());

            case LocalizableStringType.Alternate:
            case LocalizableStringType.Answer:
            case LocalizableStringType.Note:
                return(Localizations.FindQuestionGroup(key)?.GetQuestionSubGroup(key.Type)?.TranslationUnits.SingleOrDefault(tu => tu.English == key.SourceUIString));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        internal TranslationUnit GetLocalizableStringInfo(UIDataString key)
        {
            if (String.IsNullOrWhiteSpace(key?.SourceUIString))
            {
                return(null);
            }

            if (key.Type == LocalizableStringType.Category)
            {
                return(Localizations.Categories.TranslationUnits.SingleOrDefault(tu => tu.English == key.SourceUIString));
            }
            if (key.Type == LocalizableStringType.SectionHeading)
            {
                return(Localizations.Groups.SingleOrDefault(g => g.Id == FileBody.GetSectionId(key))?.TranslationUnits?.Single());
            }

            var question = Localizations.FindQuestionGroup(key);

            if (question == null)
            {
                return(null);
            }
            switch (key.Type)
            {
            case LocalizableStringType.Question:
                return(question.TranslationUnits?.SingleOrDefault());

            case LocalizableStringType.Answer:
            case LocalizableStringType.Note:
            case LocalizableStringType.Alternate:
                return(question.GetQuestionSubGroup(key.Type)?.
                       TranslationUnits.SingleOrDefault(tu => tu.English == key.SourceUIString));

            default:
                throw new Exception("Unhandled type!");
            }
        }
Esempio n. 15
0
        public void HttpPostWithFilesAndParameters2()
        {
            // this method sends a file and checks for the number of bytes recieved
            HttpClient client     = new HttpClient();
            HttpPost   postMethod = new HttpPost(new Uri(Constants.HTTP_MULTIPART_POST_200));

            MultipartEntity multipartEntity = new MultipartEntity();

            string fileName = "big-text.txt";

            FileInfo fi        = ResourceManager.GetResourceFileInfo(fileName);
            FileBody fileBody1 = new FileBody("file", fileName, fi, "text/plain");

            multipartEntity.AddBody(fileBody1);
            postMethod.Entity = multipartEntity;

            StringBody stringBody1 = new StringBody(Encoding.ASCII, "param1", "value1");

            multipartEntity.AddBody(stringBody1);
            StringBody stringBody2 = new StringBody(Encoding.ASCII, "param2", "!#$^&*((<>");

            multipartEntity.AddBody(stringBody2);

            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string      responseString = EntityUtils.ToString(response.Entity);
            MessageData md             = new MessageData();

            md.PostParameters.Add(new NameValuePair("param1", "value1"));
            md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>"));
            md.Files.Add(new NameValuePair(fileName, fi.Length.ToString()));
            Assert.AreEqual(md.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_MULTIPART_POST_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
        public TranslationUnit AddLocalizationEntry(UIDataString data, string localizedString = null, bool isLocalized = true, int specificSection = 0)
        {
            if (String.IsNullOrWhiteSpace(data?.SourceUIString))
            {
                throw new ArgumentException("Invalid key!", nameof(data));
            }

            InitializeLookupTable();

            TranslationUnit existing;
            Group           group = null;
            var             type  = data.Type;

            if (type == LocalizableStringType.Category)
            {
                existing = Localizations.Categories.TranslationUnits.SingleOrDefault(c => c.Id == data.SourceUIString);
                if (existing == null)
                {
                    return(Localizations.Categories.AddTranslationUnit(data, localizedString, isLocalized));
                }
            }
            else if (type == LocalizableStringType.SectionHeading)
            {
                var id = FileBody.GetSectionId(data);
                existing = Localizations.Groups.FirstOrDefault(g => g.Id == id)?.TranslationUnits.Single();
                if (existing == null)
                {
                    var sectionGroup = new Group {
                        Id = id
                    };
                    Localizations.Groups.Add(sectionGroup);
                    sectionGroup.SubGroups = new List <Group>();
                    return(sectionGroup.AddTranslationUnit(data, localizedString, isLocalized));
                }
            }
            else
            {
                var sectionGroup = Localizations.FindSectionsForQuestion(data).Skip(specificSection).FirstOrDefault();
                Debug.Assert(sectionGroup != null);
                group = sectionGroup.FindQuestionGroup(data.Question) ?? AddQuestionGroup(sectionGroup, data);
                switch (type)
                {
                case LocalizableStringType.Question:
                    existing = group.TranslationUnits?.FirstOrDefault();
                    break;

                case LocalizableStringType.Alternate:
                    group    = group.SubGroups?.SingleOrDefault(g => g.Id == FileBody.kAlternatesGroupId) ?? group.AddSubGroup(FileBody.kAlternatesGroupId);
                    existing = group.TranslationUnits?.FirstOrDefault(a => a.English == data.SourceUIString);
                    break;

                case LocalizableStringType.Answer:
                    group    = group.SubGroups?.SingleOrDefault(g => g.Id == FileBody.kAnswersGroupId) ?? group.AddSubGroup(FileBody.kAnswersGroupId);
                    existing = group.TranslationUnits?.FirstOrDefault(a => a.English == data.SourceUIString);
                    break;

                case LocalizableStringType.Note:
                    group    = group.SubGroups?.SingleOrDefault(g => g.Id == FileBody.kNotesGroupId) ?? group.AddSubGroup(FileBody.kNotesGroupId);
                    existing = group.TranslationUnits?.FirstOrDefault(a => a.English == data.SourceUIString);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (existing == null)
            {
                Debug.Assert(group != null);
                return(group.AddTranslationUnit(data, localizedString, isLocalized));
            }
            existing.Target.Text        = localizedString;
            existing.Target.IsLocalized = isLocalized;
            return(existing);
        }
Esempio n. 17
0
 private void RecieveFileMessage(FileBody body)
 {
     AppendRevHtml(String.Format("<div>收到文件:{0}({1})</div>", body.filename, body.file_length));
 }
Esempio n. 18
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="toUser">发给谁</param>
        /// <param name="postedfile">已经上传的文件返回信息</param>
        public void SendFile(string toUser, PostedFileResp postedfile)
        {
            Jid to   = new Jid(BuildJid(toUser));
            Jid from = new Jid(BuildJid(UserName));

            BodyBase[] bodies = new BodyBase[postedfile.entities.Length];
            // 构建发送文件的 message 消息
            for (int i = 0; i < postedfile.entities.Length; i++)
            {
                PostFileEntity entity = postedfile.entities[i];
                // 文件类型 img audio
                string otype = SdkUtils.GetFileType(entity.filename);
                // 文件的url
                string ourl      = postedfile.uri + "/" + entity.uuid;
                string osecret   = entity.share_secret;
                string ofilename = entity.filename;

                /*
                 * 传图片
                 * ReceivedData:
                 * <message xmlns='jabber:client' from='easemob-demo#[email protected]/webim'
                 * to='easemob-demo#[email protected]' id='124420481838219668' type='chat'>
                 * <body>
                 * {"from":"weigang75","to":"march3","bodies":
                 * [{"type":"img","url":"https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles/cd6f8050-81f7-11e5-a16a-05187e341cb0",
                 * "secret":"zW-AWoH3EeWmJevV5n4Fpkxnnu3e5okMLIhENE0QHaZbvqg5",
                 * "filename":"原生+自定义.jpg",
                 * "thumb":"https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles/cd6f8050-81f7-11e5-a16a-05187e341cb0",
                 * "thumb_secret":"","size":{"width":952,"height":671}}],"ext":{}}</body></message>
                 *
                 * 传语音
                 * ReceivedData:
                 * <message xmlns='jabber:client' from='easemob-demo#[email protected]/webim'
                 * to='easemob-demo#[email protected]' id='124421298246910356' type='chat'>
                 * <body>
                 * {"from":"weigang75","to":"march3","bodies":
                 * [{"type":"audio",
                 * "url":"https://a1.easemob.com/easemob-demo/chatdemoui/chatfiles/3ec2bb50-81f8-11e5-8e7c-1fa6315dec2d",
                 * "secret":"PsK7WoH4EeWwmIkeyVsexnkK-Rmqu2X_N2qqK9FQYmUkko8W",
                 * "filename":"环信通讯 - 副本.mp3",
                 * "length":3}],"ext":{}}</body></message>
                 *
                 */

                // 如果是文件,需要多一些字段 thumb、thumb_secret、size
                if ("img".Equals(otype))
                {
                    bodies[i] = new ImageBody
                    {
                        type         = otype,
                        url          = ourl,
                        secret       = osecret,
                        filename     = ofilename,
                        thumb        = ourl,
                        thumb_secret = "",
                        size         = new ImageSize
                        {
                            width  = entity.imageSize.Width,
                            height = entity.imageSize.Height
                        }
                    };
                }
                else if ("audio".Equals(otype))
                {
                    bodies[i] = new AudioBody
                    {
                        type     = otype,
                        url      = ourl,
                        secret   = osecret,
                        filename = ofilename
                    };
                }
                else
                {
                    bodies[i] = new FileBody
                    {
                        type     = otype,
                        url      = ourl,
                        secret   = osecret,
                        filename = ofilename
                    };
                }
            }

            MsgData data = new MsgData()
            {
                from = UserName, to = toUser, bodies = bodies, ext = new { }
            };

            WSMessage msgNode = new WSMessage(to, from);

            msgNode.Type = MessageType.chat;
            msgNode.SetBodyData(data);

            Send(msgNode);
        }
Esempio n. 19
0
 public void Init()
 {
     instance = new FileBody();
 }
Esempio n. 20
0
 public void Init()
 {
     instance = new FileBody();
 }
Esempio n. 21
0
 /// <summary>
 /// uploads a file with data 
 /// </summary>
 /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="myAppId">ID of app</param> 
 /// <param name="fileObj">file extra data</param> 
 /// <returns>string</returns>
 public string SaveFileData (string myAppId, FileBody fileObj)
 {
      ApiResponse<string> localVarResponse = SaveFileDataWithHttpInfo(myAppId, fileObj);
      return localVarResponse.Data;
 }
        internal void GenerateOrUpdateFromMasterQuestions(QuestionSections questions, List <XmlTranslation> existingTxlTranslations = null, bool retainOnlyTranslatedStrings = false)
        {
            InitializeLookupTable();

            // Note: there are two possible sources for existing localized translations of strings: either a Transcelerator project
            // (the list passed into this method), or the content read from a previous version of the file represented by this accessor.
            var existingLocalizations = XliffRoot.File.Body;

            existingLocalizations.DeleteGroupsWithoutLocalizations();
            if (existingLocalizations.Groups == null)
            {
                existingLocalizations = null;
            }

            if (existingTxlTranslations == null && retainOnlyTranslatedStrings)
            {
                return;
            }

            InitializeLocalizations();

            if (existingTxlTranslations == null)
            {
                if (existingLocalizations == null)
                {
                    AddTranslationUnit = (group, data) => group.AddTranslationUnit(data);
                }
                else
                {
                    AddTranslationUnit = (group, data) =>
                    {
                        var tu = existingLocalizations.GetStringLocalization(data);
                        if (tu == null)
                        {
                            group.AddTranslationUnit(data);
                        }
                        else
                        {
                            group.AddTranslationUnit(tu);
                        }
                    };
                }
            }
            else
            {
                if (existingLocalizations == null)
                {
                    AddTranslationUnit = (group, data) =>
                    {
                        group.AddTranslationUnit(data, LookupTranslation(existingTxlTranslations, data));
                    };
                }
                else
                {
                    AddTranslationUnit = (group, data) =>
                    {
                        var tu = existingLocalizations.GetStringLocalization(data);
                        if (tu == null)
                        {
                            group.AddTranslationUnit(data, LookupTranslation(existingTxlTranslations, data));
                        }
                        else
                        {
                            group.AddTranslationUnit(tu);
                        }
                    };
                }
            }

            UIDataString key;

            foreach (var section in questions.Items)
            {
                var sectionGroup = new Group {
                    Id = FileBody.GetSectionId(section)
                };
                Localizations.Groups.Add(sectionGroup);
                key = new UISectionHeadDataString(new SectionInfo(section));
                AddTranslationUnit(sectionGroup, key);

                foreach (Category category in section.Categories)
                {
                    var categoryGroup = sectionGroup.AddSubGroup(category.Type);
                    if (category.Type != null)
                    {
                        if (!Localizations.Categories.TranslationUnits.Any(tu => tu.English == category.Type))
                        {
                            key = new UISimpleDataString(category.Type, LocalizableStringType.Category);
                            AddTranslationUnit(Localizations.Categories, key);
                        }
                    }

                    foreach (Question q in category.Questions.Where(q => !String.IsNullOrWhiteSpace(q.Text)))
                    {
                        if (q.ScriptureReference == null)
                        {
                            q.ScriptureReference = section.ScriptureReference;
                            q.StartRef           = section.StartRef;
                            q.EndRef             = section.EndRef;
                        }
                        // The following line handles the unusual case of the same question twice in the same verse.
                        var questionGroup = categoryGroup.SubGroups?.SingleOrDefault(qg => qg.Id == $"{FileBody.kQuestionIdPrefix}{q.ScriptureReference}+{q.PhraseInUse}");
                        if (questionGroup == null)
                        {
                            questionGroup = categoryGroup.AddSubGroup($"{FileBody.kQuestionIdPrefix}{q.ScriptureReference}+{q.PhraseInUse}");
                            key           = new UIQuestionDataString(q, true, false);
                            AddTranslationUnit(questionGroup, key);
                        }

                        AddAlternatesSubgroupAndLocalizableStringsIfNeeded(q, questionGroup);
                        AddAnswerOrNoteSubgroupAndLocalizableStringsIfNeeded(q, questionGroup, LocalizableStringType.Answer, qu => qu.Answers);
                        AddAnswerOrNoteSubgroupAndLocalizableStringsIfNeeded(q, questionGroup, LocalizableStringType.Note, qu => qu.Notes);
                    }
                }
            }

            if (retainOnlyTranslatedStrings)
            {
                Localizations.DeleteGroupsWithoutLocalizations();
            }

            AddTranslationUnit = null;
        }
Esempio n. 23
0
        /// <summary>
        /// uploads a file with data 
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="myAppId">ID of app</param>
        /// <param name="fileObj">file extra data</param>
        /// <returns>Task of string</returns>
        public async System.Threading.Tasks.Task<string> SaveFileDataAsync (string myAppId, FileBody fileObj)
        {
             ApiResponse<string> localVarResponse = await SaveFileDataAsyncWithHttpInfo(myAppId, fileObj);
             return localVarResponse.Data;

        }
Esempio n. 24
0
        /// <summary>
        /// uploads a file with data 
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="myAppId">ID of app</param>
        /// <param name="fileObj">file extra data</param>
        /// <returns>Task of ApiResponse (string)</returns>
        public async System.Threading.Tasks.Task<ApiResponse<string>> SaveFileDataAsyncWithHttpInfo (string myAppId, FileBody fileObj)
        {
            // verify the required parameter 'myAppId' is set
            if (myAppId == null) throw new ApiException(400, "Missing required parameter 'myAppId' when calling SaveFileData");
            // verify the required parameter 'fileObj' is set
            if (fileObj == null) throw new ApiException(400, "Missing required parameter 'fileObj' when calling SaveFileData");
            
    
            var localVarPath = "file/{my_app_id}";
    
            var localVarPathParams = new Dictionary<String, String>();
            var localVarQueryParams = new Dictionary<String, String>();
            var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
            var localVarFormParams = new Dictionary<String, String>();
            var localVarFileParams = new Dictionary<String, FileParameter>();
            Object localVarPostBody = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
            if (localVarHttpHeaderAccept != null)
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (myAppId != null) localVarPathParams.Add("my_app_id", Configuration.ApiClient.ParameterToString(myAppId)); // path parameter
            
            
            
            
            if (fileObj.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(fileObj); // http body (model) parameter
            }
            else
            {
                localVarPostBody = fileObj; // byte array
            }

            

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, 
                Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, 
                localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int) localVarResponse.StatusCode;
 
            if (localVarStatusCode >= 400)
                throw new ApiException (localVarStatusCode, "Error calling SaveFileData: " + localVarResponse.Content, localVarResponse.Content);
            else if (localVarStatusCode == 0)
                throw new ApiException (localVarStatusCode, "Error calling SaveFileData: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);

            return new ApiResponse<string>(localVarStatusCode,
                localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                (string) Configuration.ApiClient.Deserialize(localVarResponse, typeof(string)));
            
        }