public async Task saveFileAndGetRelation() { var obj1 = new CB.CloudObject("Employee"); var obj2 = new CB.CloudObject("Company"); obj1.Set("Name", "abcd"); obj1.Set("Name", "pqrs"); byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); await file.SaveAsync(); var obj = new CB.CloudObject("Sample"); obj2.Set("File", file); obj1.Set("Company", obj2); await obj1.SaveAsync(); var query = new CB.CloudQuery("Employee"); query.Include("Company.File"); query.EqualTo("id", obj1.ID); var response = (List <CB.CloudObject>) await query.FindAsync(); Assert.IsTrue(true); }
public async Task deleteFileWithDataAndName() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); await file.SaveAsync(); if (file.Url != null) { await file.DeleteAsync(); if (file.Url == null) { Assert.IsTrue(true); } else { Assert.Fail("File delete error"); } } else { Assert.Fail("Unable to get the url"); } }
public async Task returnFileWithCloudObject() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); await file.SaveAsync(); if (file.Url != null) { var obj = new CB.CloudObject("Company"); obj.Set("File", file); await obj.SaveAsync(); var fileObj = (CB.CloudFile)obj.Get("File"); if (fileObj.Url != null) { Assert.IsTrue(true); } else { Assert.Fail("Did not get the file object back."); } } }
public async Task saveFileDataAndNameThenFetch() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); await file.SaveAsync(); var obj = new CB.CloudObject("Sample"); obj.Set("file", file); obj.Set("name", "abcd"); await obj.SaveAsync(); var fileObj = (CB.CloudFile)obj.Get("file"); if (fileObj.Url != null) { Assert.IsTrue(true); } else { Assert.Fail("Unable to fetch the file"); } }
public void saveFileDataAndName() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); var rsponse = file.SaveAsync(); Assert.IsTrue(true); }
private static byte[] GetMultipartFormData(Dictionary <string, object> postParameters, string boundary) { Stream formDataStream = new System.IO.MemoryStream(); bool needsCLRF = false; ASCIIEncoding encoding = new ASCIIEncoding(); foreach (var param in postParameters) { if (needsCLRF) { formDataStream.Write(encoding.GetBytes("\r\n"), 0, encoding.GetByteCount("\r\n")); } needsCLRF = true; if (param.Value is CB.CloudFile) { CB.CloudFile fileToUpload = (CB.CloudFile)param.Value; // Add just the first part of this param, since we will write the file data directly to the Stream string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\";\r\nContent-Type: {3}\r\n\r\n", boundary, param.Key, fileToUpload.FileName ?? param.Key, fileToUpload.ContentType ?? "application/octet-stream"); formDataStream.Write(encoding.GetBytes(header), 0, encoding.GetByteCount(header)); // Write the file data directly to the Stream, rather than serializing it to a string. formDataStream.Write(fileToUpload.File, 0, fileToUpload.File.Length); } else { string postData = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}", boundary, param.Key, param.Value); formDataStream.Write(encoding.GetBytes(postData), 0, encoding.GetByteCount(postData)); } } // Add the end of the request. Start with a newline string footer = "\r\n--" + boundary + "--\r\n"; formDataStream.Write(encoding.GetBytes(footer), 0, encoding.GetByteCount(footer)); // Dump the Stream into a byte[] formDataStream.Position = 0; byte[] formData = new byte[formDataStream.Length]; formDataStream.Read(formData, 0, formData.Length); formDataStream.Close(); return(formData); }
public async Task shouldSaveFileAndGiveURL() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); await file.SaveAsync(); if (file.Url != null) { Assert.IsTrue(true); } else { Assert.Fail("Unable to get the url"); } }
public async Task getFileObjectWithNotReadAccess() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); file.ACL.SetPublicReadAccess(false); await file.SaveAsync(); if (file == null) { Assert.IsTrue(true); } else { Assert.Fail("Unable to get ACL working"); } }
public async Task shouldNotDeleteFileNoWriteAccess() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); file.ACL.SetPublicReadAccess(false); var response = await file.SaveAsync(); response = await response.DeleteAsync(); if (response != null) { Assert.Fail("Should not retrieve file"); } else { Assert.IsTrue(true); } }
public async Task includeOverFile() { byte[] data = System.Text.Encoding.UTF8.GetBytes(".net cloudfile testing!"); string name = "sample.txt"; string type = "txt"; var file = new CB.CloudFile(data, name, type); await file.SaveAsync(); var obj = new CB.CloudObject("Sample"); obj.Set("file", file); obj.Set("name", "abcd"); await obj.SaveAsync(); var id = obj.ID; var query = new CB.CloudQuery("Sample"); query.EqualTo("id", id); query.Include("file"); var response = (List <CB.CloudObject>) await query.FindAsync(); Assert.IsTrue(true); }
internal static async Task <Dictionary <string, Object> > SendFile(Method method, string url, CB.CloudFile cf) { Dictionary <string, Object> postData = new Dictionary <string, object>(); postData.Add("key", CB.CloudApp.AppKey); postData.Add("sdk", "java"); postData.Add("fileObj", cf); string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid()); string contentType = "multipart/form-data; boundary=" + formDataBoundary; byte[] formData = GetMultipartFormData(postData, formDataBoundary); var response = await PostFile(method.ToString(), url, "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0", contentType, formData); var responseString = new StreamReader(((HttpWebResponse)response).GetResponseStream()).ReadToEnd(); return(Util.Serializer.Deserialize(responseString)); }