public bool UpdateTableAsync(string token, string tableid, FileInfo file, bool isIncremental = false) { string incremental = "0"; string incrementalMsg = ""; if (isIncremental) { incremental = "1"; incrementalMsg = " incrementaly"; } //upload file to S3 and obtain its id from SAPI logger.Trace("uplaoding file " + file.FullName); string uploadFileId = UploadFile(file.FullName, false, false); logger.Trace("Updating table " + tableid + " with " + file.Name + incrementalMsg); var postData = new Dictionary <string, string>() { { "dataFileId", uploadFileId }, { "incremental", incremental } }; string uri = "/storage/tables/" + tableid + "/import-async"; _client.AddStringFormData(postData); var updateStream = _client.SendPostRequestReadAsStream(uri); string jobid = StreamToJson(updateStream)["id"].ToObject <string>(); WaitForTaskToFinish(jobid); return(true); }
/// <summary> /// Uploads file to S3 via SAPI /// </summary> /// <param name="filePath"></param> /// <param name="isPublic"></param> /// <param name="notify"></param> /// <returns></returns> public string UploadFile(string filePath, bool isPublic = false, bool notify = true) { // 1. prepare resource FileInfo finfo = new FileInfo(filePath); var postData = new Dictionary <string, string>() { { "isPublic", isPublic.ToString() }, { "notify", notify.ToString() }, { "name", finfo.Name }, { "sizeBytes", finfo.Length.ToString() } }; _client.AddStringFormData(postData); //_client.AddFileFormData("data", file); string prepareUri = "/storage/files/prepare"; Stream result = _client.SendPostRequestReadAsStream(prepareUri); string strResponse = new StreamReader(result).ReadToEnd(); var json = Newtonsoft.Json.Linq.JObject.Parse(strResponse); var uploadParams = json["uploadParams"]; // 2. upload directly do S3 using returned credentials var s3Client = new HttpMultipartDataClient(uploadParams["url"].ToObject <string>(), new Dictionary <string, string>()); postData = new Dictionary <string, string>() { { "key", uploadParams["key"].ToObject <string>() }, { "acl", uploadParams["acl"].ToObject <string>() }, { "signature", uploadParams["signature"].ToObject <string>() }, { "policy", uploadParams["policy"].ToObject <string>() }, { "AWSAccessKeyId", uploadParams["AWSAccessKeyId"].ToObject <string>() } }; string uploadUri = "/"; s3Client.AddStringFormData(postData, false); s3Client.AddFileFormData("file", finfo); s3Client.SendPostRequestReadAsStream(uploadUri); return(json["id"].ToObject <string>()); }