使用C#将PDF读取到NetSuite的问题

时间:2016-04-20 15:35:01

标签: c# restlet netsuite

在我的RESTlet中,我在日志中看到错误:代码: UNEXPECTED_ERROR null代码:UNEXPECTED_ERROR

var pdf = data.pdfdoc;
nlapiLogExecution('DEBUG', 'in data', pdf);

我认为传入的数据未正确读取。什么看起来不寻常?

   static void Main(string[] args)
    {
        try
        {
            FileStream stream = new FileStream(@"C:\Users\simplified.PDF", FileMode.Open, FileAccess.ReadWrite);
            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, fileBytes.Length);
            stream.Close();

            string jsonString = "{\"tranid\":\"18810\", \"pdfdoc\":\"" + fileBytes + "\"" + "}";
            WebRequest request = WebRequest.Create("https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nl?script=332&deploy=1");
            request.ContentType = "application/json";
            request.Method = "PUT";
            request.Headers.Add("Authorization:NLAuth nlauth_account=XXX, nlauth_email=test@test.com, nlauth_signature=xxx, nlauth_role=18");
            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(jsonString);
            }

            WebResponse response = request.GetResponse();
            Console.Write(response);
            Console.Read();

        }
        catch (FileNotFoundException e)
        {
            Console.Write(e);
        }
    }

编辑 - 代码现在在NetSuite中创建pdf文档但不显示内容。

的Restlet



	try
	{
		var file = datain.file;
		nlapiLogExecution('DEBUG', 'in data', file);
		var base64content = nlapiEncrypt(file, 'base64', null);
		var doc = nlapiCreateFile('mydoc2.pdf', 'PDF', base64content);
		doc.setFolder(115);
		var fileid = nlapiSubmitFile(doc);
		nlapiLogExecution('DEBUG', 'after submit', fileid);
	}




0 个答案:

没有答案