Hi Team, I am getting the following error when images uploaded to epicor…Unable to POST to Ice.BO.AttachmentSvc/UploadFile - 0 Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. Note: It works fine for very small text file…
try
{
InitializeEpicRestAPI("V1");
//Read file from Disk into a byte array
Byte[] bytes = Function.FileToByteArray(filePath);
//while (stream.DataAvailable == true)
//{
// bytes[i] = ((byte)stream.ReadByte());
// i++;
//}
//data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
String fileData = Convert.ToBase64String(bytes);
//int i = 0;
//Create the File Object to be uploaded to Epicor
var file = new
{
fileName = System.IO.Path.GetFileName(filePath),
data = fileData,
docTypeID = "ECO",
parentTable = "ProjectPhase",
metadata = new
{
_Author = "Epicor PDF Importer",
_TableName = "Erp.Project",
_TableSysRowID = Guid.NewGuid()
}
};
//System.Net.ServicePointManager.Expect100Continue = false;
//System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
//System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
//Upload the file using the Attachment BO
//EpicorRestV1.BearerToken = ""; //AsyncCallback
var addedDocFile = EpicorRestV1.DynamicPost("Ice.BO.AttachmentSvc", "UploadFile", file);
//addedDocFile.ds.ToString()
//Create the Epicor XFileRef
var xFileRef = new { Company = Company, XFileName = addedDocFile.ds.ToString(), XFileDesc = file.fileName, DocTypeID = "ECO" };
var addedXRef = EpicorRestV1.DynamicPost("Ice.BO.XFileRefSvc", "XFileRefs", xFileRef);
// Once the XFileRef exists attach it to a UD103 record.
var ProjPhaseAttch = new
{
Company = Company,
ProjectID = ProjectID,
PhaseID = PhaseID ,
FileName = addedXRef.XFileName,
DrawDesc = addedXRef.XFileDesc,
DocTypeID = file.docTypeID,
ForeignSysRowID = Guid.NewGuid(),
RowMod = "U"
};
dynamic newUDAttch = EpicorRestV1.DynamicPost("Erp.BO.ProjectSvc", "ProjPhaseAttches", ProjPhaseAttch);
//return strRetValue;
}
catch (Exception e)
{
//Console.WriteLine(e + "");
strResult = e.Message;
}