public void AttachableUploadDownloadAddTestUsingoAuth() { //Creating the Bill for Add string imagePath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "\\", "Services\\Resource\\image.jpg"); System.IO.FileInfo file = new System.IO.FileInfo(imagePath); Attachable attachable = QBOHelper.CreateAttachableUpload(qboContextoAuth); using (System.IO.FileStream fs = file.OpenRead()) { attachable.ContentType = "image/jpeg"; attachable.FileName = file.Name; attachable = Helper.Upload(qboContextoAuth, attachable, fs); } byte[] uploadedByte = null; using (System.IO.FileStream fs = file.OpenRead()) { using (BinaryReader binaryReader = new BinaryReader(fs)) { uploadedByte = binaryReader.ReadBytes((int)fs.Length); } } //Verify the added Attachable Assert.IsNotNull(attachable.Id); byte[] responseByte = Helper.Download(qboContextoAuth, attachable); for (int i = 0; i < responseByte.Length; i++) { Assert.AreEqual(uploadedByte[i], responseByte[i]); } }
//This is the endpoint for actual uppload of any attachments pdf/images/xls etc public void AttachableUploadDownloadAddTestUsingoAuth(ServiceContext qboContextoAuth) { string imagePath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "\\", "Resource\\invoice.pdf"); System.IO.FileInfo file = new System.IO.FileInfo(imagePath); Attachable attachable = QBOHelper.CreateAttachableUpload(qboContextoAuth); using (System.IO.FileStream fs = file.OpenRead()) { //attachable.ContentType = "image/jpeg"; attachable.ContentType = "application/pdf"; attachable.FileName = file.Name; attachable = Helper.Upload(qboContextoAuth, attachable, fs); } //Upload attachment byte[] uploadedByte = null; using (System.IO.FileStream fs = file.OpenRead()) { using (BinaryReader binaryReader = new BinaryReader(fs)) { uploadedByte = binaryReader.ReadBytes((int)fs.Length); } } //To read online file //using (MemoryStream fs1 = new MemoryStream()) //{ // using (BinaryReader binaryReader = new BinaryReader(fs1)) // { // uploadedByte = binaryReader.ReadBytes((int)fs1.Length); // } //} //Dowload Attachment byte[] responseByte = Helper.Download(qboContextoAuth, attachable); }