Not able to send attachment through Rest API call to Rollbase. Any one can share working code to send attachment
Here is the code
string mypath = Path.Combine(Path.GetTempPath(), attachment.DisplayName); //Store email attachment file
attachment.SaveAsFile(mypath);
FileInfo file = new FileInfo(attachment.DisplayName);
string contenttye = "Applicaion/" + file.Extension.Replace(".",string.Empty);
byte[] byteArray = System.IO.File.ReadAllBytes(mypath);
string urlattachmen = string.Format("{0}create2?sessionId={1}&objName=$R_DOCS&file={2}&R2465433={3}&output=json", API_Method.Utils.GlobalURL, Globals.ThisAddIn.SessionID,mypath, o["id"].ToString());
System.Net.WebRequest reqs = System.Net.WebRequest.Create(urlattachmen);
reqs.ContentType="Content-Type,"+ "application/x-www-form-urlencoded; charset=UTF-8";
reqs.Method = "Get";
reqs.ContentLength = byteArray.Length;
//true means no proxy
System.Net.WebResponse resps = reqs.GetResponse();
System.IO.StreamReader srs = new System.IO.StreamReader(resps.GetResponseStream());
string result = srs.ReadToEnd().Trim();
File.Delete(mypath);
Hello Anu,
If you are trying to attach a document for the created record, then you can use REST API setBinaryData by passing the base-64 encoded binary value of the file. This will attach the file to 'file upload' field.
Hope this helps.
Thanks,
Sopna.
First a disclaimer that I have not done this myself, but looking at the doc in Ch. 15 of Rollbase in Action....
Is your use case one where you want the File Upload field? ( the code snippet you provided looked like you might be trying something else )
Reply by Bill WoodFirst a disclaimer that I have not done this myself, but looking at the doc in Ch. 15 of Rollbase in Action....
- create2 (or update2) don't seem to allow the content-type on attachments.
- setDataDef does support setting the value of a File Upload field. The doc for this in REST API section may give you a hint on how to go forward.
Is your use case one where you want the File Upload field? ( the code snippet you provided looked like you might be trying something else )Stop receiving emails on this subject.Flag this post as spam/abuse.
Hello Anu,
If you are trying to attach a document for the created record, then you can use REST API setBinaryData by passing the base-64 encoded binary value of the file. This will attach the file to 'file upload' field.
Hope this helps.
Thanks,
Sopna.
Are asking to try with similar code as below. I am going to try tonight
string mypath = Path.Combine(Path.GetTempPath(), attachment.DisplayName); //Store email attachment file
attachment.SaveAsFile(mypath);
FileInfo file = new FileInfo(attachment.DisplayName);
string contenttye = "Applicaion/" + file.Extension.Replace(".",string.Empty);
byte[] byteArray = System.IO.File.ReadAllBytes(mypath);
// Convert the binary input into Base64 UUEncoded output. string base64String;
try { base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
} catch (System.ArgumentNullException) { System.Console.WriteLine("Binary data array is null.");
return;
}
Call the Rollbase RestAPI
setBinaryData?sessionId={1}&id={2}&fieldname=FileUploadFieldName&value =binData &contentType="application/pdf"&fileName="invoice.pdf"
Hello,
I am trying to achieve the same with a .pptx file but I am unable to do so. Could you please suggest me on how do I set the binary data with a .pptx file? I have tried the following: community.progress.com/.../50278.aspx
Please remove spaces and quotes from your URL.